Publishing Web Games with Unity

I recently started delving into creating assets for the Unity Asset store and one of the main things people look at when deciding if an asset is good or not is how it plays in an interactive demo. This is done via a web demo published from Unity. One of Unity’s strengths is the ability to build your game for the web. There are two versions of web platforms you can build for within Unity 5; Web and Web GL. We’ll take a look at how we can use the default “Web Player” platform that has been around for a while. Below is a simple demo I made: http://xenosmashgames.com/m11-demo/ *Note* currently Chrome does not support the old Unity Web player. Firefox is still supporting it though as of the writing of this article In that link you'll find a single post containing the Unity web demo for an asset. The question then is how do we get our asset (or complete game) from Unity into a web-friendly format? Let's first take a look at building your game within Unity. No matter the size of your game you'll need to ensure your build settings are setup in order to build for the web. By default a Unity project will be set to PC, Mac, & Linux Standalone. You'll need to switch platforms by selecting "Web Player" at the very top of the list and clicking Switch Platform. buildSettings Next you'll need to ensure your scenes are included in the area marked as Scenes in Build. If you have no scenes here you can drag them in from your project panel and/or you can also use "add current" which can add the current scene in. Ensure these scenes are in the proper order starting with 0. Feel free to adjust various settings for the web platform such as icons, default resolutions, app information by clicking the Player Settings button. Once you've filled in the info/icons you want click on Build in the Build settings window. Unity will ask you where you want to save this build and typically I save it in my project just to keep things in the same place. Once that is done your game should start building. Depending on the size of your game this process may take a while. After finishing Unity may open up the folder the game was saved to. unityFilesIf you want to test your built game on your machine just open the .html file Unity created for you within your browser. You may need to install the Unity web player for this to work, it's one of the downsides to web games with Unity but is required for the time being. Next we'll take a look at uploading the required files to be used on a Wordpress blog or website.

Uploading Unity files and Publishing to Your Site

Once you've tested your game and you're ready to publish to your site you'll need a few files for this to work:
  • .html file (not the index.html file) with the name of your game
  • .unity3d file with the name of your game
Both of these are required in order to display and properly play your game in a web platform. Players will also need to have the Unity web player installed but that is something they need to do themselves. For the HTML file you'll want to open this up in a text editor of some sort. You'll want to locate the area that has a link to the .unity3d file as this needs to be updated to the location of where you want to upload this file. It will have the name of your game followed by .unity3d. So in my case mine was called "testGame.Unity3d" and you'd need to replace that file with something like "yourwebsite.com/testGame.unity3d". Below is a screenshot of the highlighted area that you need to be looking for: UnityLinkThere are a few ways I've personally uploaded this file online:
  • Onto my own Wordpress server through FTP
  • Amazon S3 with a public link
I've tried using this with Dropbox and have had issues personally but it may work for you. Either way you'll need to ensure you have the direct link to this file. The next step is to copy the HTML code and paste that into a page on your site. In my case I used a Wordpress site and pasted the code directly into a post. If you go this route make sure you're in text mode and not visual as it may cause issues with formatting. Paste the code in and change the link. Depending on the height/width you selected for your player you may need to adjust this to fit within your site. The good news is you can change all this directly from the HTML code. If all went well you should be able to see this player within your site now, hooray!

wordpressPost

What about Web GL?

Web GL is supposed to be the new way of publishing and playing web games. It's faster, and easier to manage and more importantly for Unity, doesn't require the Unity web player plugin. Unity's Web GL is currently supported by Chrome and FireFox. Initially I created my demo linked above with Web GL and it still has a long way to go. Some issues I experienced included loss of sound clips and muddy textures. There where no changes in resolution or different angles within my game between the Web GL version and the regular Web version. This was a bit of a bummer but to be fair Web GL within Unity is still very much a work in progress. It may work great for some people, but at this point I believe you should stick with the traditional web publishing method posted above before putting all your eggs into the Web GL basket. I'm excited to see the future of web games especially with all the performance upgrades made to enable really powerful games to run within a browser. I hope this article has helped to get your games out there as it's one of the easiest ways to publish a game online. If you have any questions or comments feel free to comment below or find me on the community forums.

Newsletter Signup

Get fresh Blender content, training and offers straight to your inbox. Change your mind, unsubscribe at any time.

No comments found.

CG Cookie

Learn Art. Make Dough.

Enroll in to our digital arts program and choose from four different disciplines; each with quick paths to measured success baked just for you.

Start your Free TrialorLearn More