Until now we’ve only been testing or playing our game inside the Unity Editor, but at some point, we want to build our game. This allows us to test the game in a standalone environment, or to deploy it to a platform of our choice.
Out of the box, Unity supports a wide variety of platforms including PC, Mac, Android, iOS, PlayStation and more. We can even build our game as a WebGL application that can run the game in a browser.
Today I’ll be building my game for two platforms. Firstly I’ll build it for PC to test our game and secondly I’ll build a WebGL version and show where to upload it for others to play.
Let’s Build for Windows
Let’s start by clicking on “File” then click on “Build Settings”. Once the Build Settings window appears you’ll see a variety of build options. If your chosen build setting isn’t on the list then you can install it by modifying the installation in the Unity Hub. But back in Unity with the Build Settings window open, we need to check that we have added the scenes we want to the scenes list. This is very important because if you don’t add those scenes to the list then the game will be built without those scenes and will cause undesirable effects.
In my project, I have a “MainMenu” and “Game” Scene so I checked that both are added. By default, Unity will select the “PC, Mac, & Linux Standalone” as the platform to build to. In my case, I want to build for Windows so under the “Target Platform” I selected windows. Once you’re happy with the settings then you can click on the “Build” Button.
Unity will now ask where to save the files and I chose to create a folder on the Desktop and built my game in that folder.
Unity will open the folder once the project has been built and you’ll get a message in the console to say that the build was completed.
Building for WebGL
Building your project to upload is similar to how we did for windows. But instead of selecting “PC, Mac, & & Linux Standalone” we need to select WebGL.
Before you can build for WebGL you need to click the “Switch Platform” Button. This will cause Unity to recompile its scripts and make changes to assets so that everything is optimized for the web.
Once Unity is done recompiling you can click on the “Build” button and specify a folder where you want to save your files. Please take note that building to WebGL takes quite a bit longer.
Once the project is done building then the next step is to upload your game to an online service where other people like friends and family can play your game, but we’ll be covering that in another article.