Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 2020 By Example

You're reading from   Unity 2020 By Example A project-based guide to building 2D, 3D, augmented reality, and virtual reality games from scratch

Arrow left icon
Product type Paperback
Published in Sep 2020
Publisher Packt
ISBN-13 9781800203389
Length 676 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Robert Wells Robert Wells
Author Profile Icon Robert Wells
Robert Wells
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Chapter 1: Exploring the Fundamentals of Unity 2. Chapter 2: Creating a Collection Game FREE CHAPTER 3. Chapter 3: Creating a Space Shooter 4. Chapter 4: Continuing the Space Shooter Game 5. Chapter 5: Creating a 2D Adventure Game 6. Chapter 6: Continuing the 2D Adventure 7. Chapter 7: Completing the 2D Adventure 8. Chapter 8: Creating Artificial Intelligence 9. Chapter 9: Continuing with Intelligent Enemies 10. Chapter 10: Evolving AI Using ML-Agents 11. Chapter 11: Entering Virtual Reality 12. Chapter 12: Completing the VR Game 13. Chapter 13: Creating an Augmented Reality Game Using AR Foundation 14. Chapter 14: Completing the AR Game with the Universal Render Pipeline 15. Other Books You May Enjoy

Building the game

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:

  1. Select File | Build Settings... from the Application menu:
    Figure 2.38 – Accessing the Build Settings for the project

    Figure 2.38 – Accessing the Build Settings for the project

  2. The Build Settings dialog is then displayed. The Scenes In Build section contains a list of all scenes to be included in the build, regardless of whether the gamer will visit them in the game. In short, if you want a scene in your game, then it needs to be on this list. If the list is empty, make sure that the game scene is open and then click Add Open Scenes:
    Figure 2.39 – Adding a level to the Build Settings dialog

    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.

  3. Next, be sure to select your target platform from the Platform list on the bottom left-hand side of the Build Settings dialog. For desktop platforms, choose PC, Mac & Linux Standalone, which should be selected by default. Then, from the options, set the Target Platform drop-down list to either Windows, Linux, or Mac OS X, depending on your system:
    Figure 2.40 – Choosing a target build platform

    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.

  4. Before building for the first time, you'll probably want to view the Player Settings… options to fine-tune important build parameters, such as game resolution, quality settings, executable icon, and information, among other settings. To access the player settings, click on the Player Settings… button from the Build Settings dialog or select Edit | Project Settings in the application menu and then click on Player in the new panel that opens.
  5. From the Player settings options, set the Company Name and Product Name as this information is baked and stored within the built executable. You can also specify an icon image for the executable, as well as a default mouse cursor if one is required. For the collection game, however, these latter two settings will be left empty:
    Figure 2.41: Setting Company Name and Product Name

    Figure 2.41: Setting Company Name and Product Name

  6. The Resolution and Presentation tab is especially important as it specifies the game screen size and resolution. From this tab, ensure that Fullscreen Mode is set to Full screen Window, so that the game will use the total size of the system's screen as opposed to a smaller, movable window:
    Figure 2.42 – Enabling Fullscreen mode

    Figure 2.42 – Enabling Fullscreen Mode

  7. Now you're ready to compile your first build! Click on the Build button from the Build Settings dialog or choose File | Build And Run from the application menu:
    Figure 2.43 – Building and running a game

    Figure 2.43 – Building and running a game

  8. When you do this, Unity presents you with a Save dialog, asking you to specify a target location on your computer where the build should be made. Select a location and choose Save, and the build process will be completed.

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

Figure 2.44 – Unity builds several files

It's worth quickly running through what each file and folder contains:

  • The 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

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.

You have been reading a chapter from
Unity 2020 By Example - Third Edition
Published in: Sep 2020
Publisher: Packt
ISBN-13: 9781800203389
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image