-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Unity 5.x By Example
By :
In this section, I will take you through how to compile and package the game into a standalone and self-executing form that anyone can run and play without requiring the Unity editor. Typically, when developing games, you'll decide your target platform (such as Windows, iOS, Android, and others) during the design phase and not at the end of development. It's often said that Unity is a develop once, deploy everywhere tool. This slogan can conjure up the unfortunate image that, after a game is made, it'll work just as effortlessly on every platform supported by Unity as it does on the desktop.
Unfortunately, things are not so simple; games that work well on desktop systems don't necessarily perform equally well on mobiles and vice versa. This is primarily due to the significant differences in target hardware and industry standards that hold between them. Due to these differences, we'll focus our attention here on the Windows and Mac desktop platforms, ignoring mobiles and consoles and other platforms (for now). To create a build for a desktop platform, take the following steps:

Figure 2.38 – Accessing the Build Settings for the project

Figure 2.39 – Adding a level to the Build Settings dialog
Tip
You can also add scenes to the list by dragging and dropping the scene asset from the Project panel to the Scenes In Build list.
Unity automatically assigns scenes a number, depending on their order in the list. 0 represents the first item, 1 the next item, and so on. The first scene (scene 0) will always be the starting scene. When the build runs, Unity automatically begins execution from scene 0. For this reason, scene 0 will typically be your splash or intro scene.

Figure 2.40 – Choosing a target build platform
Important note
If you've previously been testing your game for multiple platforms or trying out other platforms such as Android and iOS, the Build button (shown in Figure 2.40) may instead say Switch Platform when you select the Standalone option. If it does, click on the Switch Platform button to confirm to Unity that you intend to build for that platform. On clicking this, Unity may spend a few minutes configuring your assets for the selected platform.

Figure 2.41: Setting Company Name and Product Name

Figure 2.42 – Enabling Fullscreen Mode

Figure 2.43 – Building and running a game
Occasionally, this process can generate errors, which are printed in red in the Console window. This can happen, for example, when you save to a read-only drive, have insufficient hard drive space, or don't have the necessary administrative privileges on your computer. However, generally, the build process succeeds if your game runs properly in the editor.
After the build is complete, Unity generates new files at your destination location. On macOS, it generates an app file that contains all the necessary data to run the game. On Windows, it will create a folder containing the executable and several other files, as shown in Figure 2.44:
Figure 2.44 – Unity builds several files
It's worth quickly running through what each file and folder contains:
CollectionGame_Data folder contains all the data necessary to run the project.CollectionGame.exe is the executable, the entry point into our game. Run this to play the game.MonoBleedingEdge contains the C# and MonoDevelop libraries required by our game.UnityCrashHandler64.exe has the same lifetime as your game. It is automatically started and closed with the game and handles any crashes that occur.UnityPlayer.dll contains the native Unity engine code required by our game.The files are essential and interdependent. If you want to distribute your game and have other people play it without needing to install Unity, you'll need to send users both the executable file and associated data folders and all their contents.
By running CollectionGame.exe on Windows or CollectionGame.app on macOS, the game will start:
Figure 2.45 – Running the coin collection game in Fullscreen mode
Tip
As there's no quit button or main menu option, to quit the game press Alt + F4 (Windows), cmd + Q (macOS), or Ctrl + Q (Linux).
Congratulations! Your game is now completed and built, and you can send it to your friends and family for playtesting.
Change the font size
Change margin width
Change background colour