Objective: deploy your build as a WebGL to run on the Web, and use the Servez web server tool for testing on your local machine.
Making a build for WebGL begins the same way as any other build in Unity. Go to File, Build Settings…, and select WebGL as your Platform. If this is your first build on WebGL, you will need to select the Switch Platform button on the bottom right.
Unity will then recompile all of its scripts in preparation for a WebGL environment.
If not already done so, you will also need to resolve the Color Space setting by going into Player Settings…, and in the settings for WebGL, select Other Settings and change the Rendering / Color Space from Linear to Gamma. Close the Project Settings window and you’re good to go!
To dig deeper into WebGL development, you can find more information from the Unity manual here.
Once ready to go, select Build, select a folder location in which to save, and Unity will then compile your project. You will then find the following three items in your destination folder:
If you had a HTML server, you could then take these three files and save them to your server and play your game. Unfortunately, if all you have is your standalone platform, you will get the following error:
Now, there are various ways to test your build prior uploading to a server. What I’m about to present is a fairly simple solution using a program called Servez.
Servez is a simple web server for local web development and it can be found here.
Go ahead and download/install the required version for your machine. Upon execution, Servez will open the GUI shown to the left. Go ahead and select the folder location of your WebGL build, press Start, and Launch Browser to test your project.
There you have it. I hope you enjoyed this simple guide on WebGL builds, along with the solution demonstrated to test on your local machine using Servez. Thanks for reading! :)