Have you been working on Unity projects and wanted a way to host your games for free so other people may experience them? With the use of GitHub Pages makes this possible for you to host a build of your Unity project!
Create a WebGL build in Unity
Unity has a build option available that allows you to create a build of your project that can be played in a browser.
Here are the steps to create a WebGL build:
- File > Build Settings > HTML5/WebGL.
- Install the module if you don’t already have it. This will require restarting Unity.
- Player settings > Set the resolution, check run in background, and choose a template.
- Click the Build button.
This will create an index.html file and Build/ directory. Depending on the template you chose, it may also create a TemplateData/ directory. You should be able to point your browser at your local index.html and be able to play your build, next we are going to get the build up on GitHub.
Push your WebGL Build to GitHub
Move index.html, Build/, and TemplateData/ to the root of your git repository. Commit and push all of these files. Your build files will be accessible online in your GitHub repository, but it will only show the file contents of what is uploaded, while we want the content to be hosted.
If you haven’t used GitHub before I have created a tutorial on how to create a repository.
Set up GitHub Pages
Next up is GitHub Pages.
GitHub Pages is a static site hosting service designed to host your personal, organization, or project pages directly from a GitHub repository.
To set this up in GitHub:
- Navigate to your repository > Settings > Pages.
- Set Source to master branch and Save.
Navigate to https://<user-name-here>.github.io/<repo-name-here> (mine is https://mattaisthorpe.github.io/sprite-unity-game/) and your game will load up. If you can’t access the page yet, give it five minutes then refresh.
There you have it! You have now uploaded a Unity build to GitHub and hosted on GitHub Pages. Here is one of my project setups to compare or check it out:
You can read more about my sprite game on my portfolio, I go through the objective of the project and what I got out of it. Thanks!