Testing and Playing Your Game Outside of Unity
When you get enough features implemented in your game, you will want to test it or let your friends play it outside of Unity. To do that, you need the export it from Unity; this is known as a Build.
To Build the game, open the Build Settings window. Unity can create a Build for many different platforms. The default Build platform for Unity is PC, Mac & Linux Standalone. Any other platform requires you to add a Module to that version of Unity to build for it.
Ensure all of the scenes you want in the Build of your game are in the Build Index. The first scene to be loaded is the one with a Build Index of 0. You usually want the first scene to be the Main Menu, so the game opens to it after the splash screen(s).
The Build Settings window has a button that will open the Player settings.
The Player Settings can change many settings for the Build, like the icon image, cursor image, default resolution and presentation, Splash Screen, and Color Mode.
PC, Mac & Linux Standalone
After the settings are the way you want them, click the Build or Build and Run button. Unity will then ask in what folder you want to create the Build. Your game will then begin to compile, and when done (if successful), a window will open showing the created executable and accompanying files of your game.
Launching the executable will load your game that you can now play outside of Unity. If you want to send the game to someone, all you need to do is Zip the folder containing the files and send it to them.
WebGL
Now let’s make WebGL Build of the game. To do that, we need to add the WebGL module to this version of Unity. You can do that two ways (well, one way, really). The first is selecting the WebGL platform in the Build Settings window and then clicking the Install with Unity Hub button. That will open Unity Hub and the Add Modules window for the Unity version of your Project with the WebGL module already selected. Click Done to install it.
The second way is to open Unity Hub, go to the Installs tab, then click the three dots icon on the version of Unity you want to install the WebGL module on, select the WebGL Build Support and click Done to install.
After installing the module, you will need to close and re-open your Project if you had it open during the install. Once you have your Project open, go to the Build Settings again and select WebGL and then click the Switch Platform button. Then Unity will recompile the Project for WebGL, after which you will be able to Build for it.
When you change the Platform to WebGL, if your Color Mode is set to Linear, you will see a warning telling you that it needs to be set to Gamma for WebGL.
Open the Player Settings and under Other Settings, change the Color Mode to Gamma. The switch can take a while, depending on the size of the Project.
Also, in Player Settings under Publishing Settings, change Compression Format to None. You want to change it to None because some of the sites you can host your WebGL Build require it uncompressed.
Once the settings are set, click the Build or Build and Run button. Unity will then ask in what folder you want to create the Build. Your game will then begin to compile, and when done, a window will open showing the created index.html and accompanying files of your game.
The following article will show a couple of ways to host the WebGL Build so people can play your game in their web browser and where you can share your Standalone Build easily.