
Introducing the first game
In the first game we will create, the player will control a character in the first person to explore an environment, collecting coins before a time limit runs out. If the timer runs out, the game is over. On the other hand, if all coins are collected before the timer expires, the player wins. The controls will use the industry-standard WASD keyboard setup, where W moves forward, A and S move left and right, and D walks backward. Head movement is controlled using the mouse, and coins are collected by colliding with them.
The benefit of developing this type of game is that it will demonstrate all the core Unity features, and we won't need to rely on any external software to make assets, such as textures, meshes, and materials.
See Figure 1.1, which features the coin collection game in action in the Unity Editor:

Figure 1.1 – The completed coin collection game
Important note
The completed CollectionGame project, as discussed in this chapter and the next, can be found in the book companion files in the Chapter02/End folder.
Now that we have an idea of the type of game we'll be making, in the next section, we can start development by creating the initial project structure.
Getting started with Unity
Every time you want to make a new Unity game, including coin collection games, you'll need to create a new project. Generally speaking, Unity uses the term project to mean a game. There are two main ways to make a new project, and it really doesn't matter which one you choose because both end up in the same place. If you're already in the Unity interface, looking at an existing scene or level, you can select File | New Project... from the application menu, as shown in Figure 1.2:

Figure 1.2 – Creating a new project via the main menu
After selecting the New Project option, Unity leads you to the project creation wizard.
Alternatively, you can create a new project using Unity Hub, as shown in Figure 1.3. Unity Hub is a standalone application that you can use not only to manage your projects, but your Unity installations as well. So, if you want to have multiple different versions of Unity installed (for example, 2019 and 2020), Unity Hub makes this easy. With Unity Hub open, you can access the new project wizard by choosing the NEW button:

Figure 1.3 – Unity Hub
On reaching the project creation wizard, Unity can generate a new project for you on the basis of a few settings:
- Fill in the name of your project (such as CollectionGame).
- Select a folder on your computer to contain the project files that will be generated automatically.
- Unity provides several project templates, as outlined here:
2D: A standard project setup for working in a 2D space. 2D-specific settings are configured for texture importing, the scene view, and the lighting and camera settings in the sample scene.
3D: A project configured to use Unity's built-in render pipeline.
3D With Extras: The same as 3D, but includes a new post-processing stack and additional sample content to show off the new processing stack.
High Definition RP: A project configured for high-end platforms. It uses a Scriptable Render Pipeline (SRP) called High Definition Render Pipeline (HDRP), which provides additional rendering control by allowing you to configure render settings using C# scripts.
Universal RP: This uses the Universal Render Pipeline (URP). This pipeline is similar to HDRP but suitable for a broader range of devices, including mobile. The URP will be explored in more detail in a later chapter.
Throughout the book, we'll create a number of 2D, 3D, and URP projects. For this project, choose the 3D option from the template section to create a 3D game.
- Finally, click on the CREATE button to complete the project generation process, as shown in Figure 1.4

Figure 1.4 – Creating a new project
Once you've clicked on CREATE, after some initial setup, the Unity editor will open. If this is your first time viewing the editor, it may seem daunting, but don't worry, I will guide you through how it all works, and you'll be creating games in no time. We'll start by taking a look at the Project panel and how we can import assets into the project, which we'll use to make our game.
Introducing the Project panel
You now have a new project. This represents the starting point for any game development in Unity. The newly created project contains an example scene, but nothing else: no meshes, textures, or any other assets. You can confirm this by checking the Project panel area at the bottom of the editor interface. This panel displays the complete contents of the project folder, which corresponds to an actual folder on your local drive created earlier by the new project wizard, as shown in Figure 1.5:

Figure 1.5 – The Unity Project panel docked at the bottom of the interface
This panel will soon be populated with more items, all of which we can use to build a game.
If your interface looks different from Figure 1.5, in terms of its layout and arrangement, then you can reset the UI layout to its defaults. To do this, click on the Layout drop-down menu from the top-right corner of the editor interface, and choose Default:

Figure 1.6 – Switching to the default interface layout
Tip
The sample scene can safely be deleted. You will be shown how to create a new scene shortly.
As well as a sample scene, Unity also includes a Packages folder, just below the Assets folder, as shown in Figure 1.5. A package is a collection of assets that can be used in your game. A new project already contains several packages, but they can be safely ignored for now, as we won't be using them for this project. We will instead install a new package shortly.
Important note
If you navigate to the Packages folder in a file browser, you may reasonably expect to see the installed packages. Instead, however, you'll be greeted with a JSON file that lists the packages included in your project. The packages are actually stored with Unity. This way, you don't need to re-download packages that are used in other projects. They can be downloaded once and shared between all of your projects as required.
You can view the contents of your project folder directly, via either Windows Explorer or Mac Finder, by right-clicking the mouse in the Project panel from the Unity Editor to reveal a context menu, and from there, choose the Show in Explorer (Windows) or Reveal in Finder (Mac) option:

Figure 1.7 – Opening the project folder via the Project panel
Clicking on Reveal in Finder displays the folder contents in the default system file browser. This view is useful to inspect files, count them, or back them up. However, don't change the folder contents manually this way via Explorer or Finder. Specifically, don't move, rename, or delete files from here; doing so can corrupt your Unity project irretrievably. Instead, delete and move files where needed within the project window in the Unity Editor. This way, Unity updates its metadata as appropriate, ensuring that your project continues to work correctly.
The common folders and files that are generated with a Unity project include:
- Assets: This is the folder where all your game's resources are stored, including scripts, textures, and audio files.
- Library: Unity processes and converts the files in the Assets folder so they are ready to be compiled in your game. The processed files are stored here.
- obj: This folder stores temporary files generated by MonoDevelop when a project is built.
- Temp: This folder also stores temporary files, but these files are generated by Unity during the build process.
- Packages: As mentioned previously, this folder contains a JSON file with a list of packages added to the project. More on packages shortly.
- ProjectSettings: This folder stores project-level settings, including physics, layers, tags, and time settings.
- UserSettings: This folder stores settings related to your editor; for example, if you apply a custom layout to the Unity editor, that will be saved here.
- Assembly-CSharp.csproj: This is a project file generated by MonoDevelop.
- CollectionGame.sln: This is a solution file that stores the structure of the CollectionGame project in Visual Studio (the IDE used to create the C# scripts).
Important note
Viewing the project folder in the OS file browser will display additional files and folders not visible in the Project panel, such as Library and ProjectSettings, and maybe a Temp folder. Together, these are known as the project metadata. They contain additional settings and preferences that Unity needs in order to work correctly. These folders and their files should not be edited or changed.
With a solid understanding of how to view assets using the Project panel, we'll next import external assets that will help us create our game.
Importing assets
Assets are the ingredients or building blocks for games—the building blocks from which they're made. There are many different types of assets, including:
- Meshes (or 3D models), such as characters, props, trees, houses, and more.
- Textures, which are image files such as JPEGs and PNGs (these determine how the surface of a mesh should look)
- Music and sound effects to enhance the realism and atmosphere of your game
- Scenes, which are 3D spaces or worlds where meshes, textures, sounds, and music live, exist, and work together holistically as part of a single system
Games cannot exist without assets—they would otherwise look completely empty and lifeless. For this reason, we'll need assets to make the coin collection game we're working toward. After all, we'll need an environment to walk around and coins to collect!
Unity, however, is a game engine and not primarily an asset creation program, like Blender or Photoshop (though it can create assets). This means that assets, such as characters and props, are typically made first by artists in external, third-party software. From here, they are exported and transferred ready-made to Unity, and Unity is only responsible for bringing these assets to life in a coherent game. Third-party asset creation programs include Blender (which is free), Maya or 3DS Max to make 3D models, Photoshop or GIMP (which is also free) to create textures, and Audacity (which again is free) to generate audio. There are plenty of other options, too. The details of these programs are beyond the scope of this book. In any case, Unity assumes that you already have assets ready to import to build a game. For the coin collection game, we'll use assets created by Unity. So, let's import these into our project.
To do this, you first need to download the Standard Asset package from the Unity Asset Store. The standard asset package contains a number of useful objects that will help us create a game. However, we'll go into the contents of this package in more detail shortly. For now, follow these steps:
- Navigate to https://assetstore.unity.com and search for Standard Assets.
- Once on the Standard Assets page, click on Add to My Assets, as shown in Figure 1.8:
Figure 1.8 – Standard Assets page on the Unity Asset Store
The Unity Asset Store is a great place to find assets made by other developers, from 3D models to complete projects. Some are free, but many can be downloaded for a small fee.
Important note
If you have difficulty in finding the Standard Asset package or it doesn't work with your version of Unity, please follow the instructions in the Entering the world section in Chapter 8, Creating Artificial Intelligence, where we write our own.
- Once the package has been added to your assets, you can find it in the Package Manager. Head back into Unity and select Window | Package Manager from the application menu:
Figure 1.9 – Opening the Package Manager window
- The Package Manager is a relatively new feature of Unity. It is used to add packages to, and remove packages from, the current project. Remember, a package is simply a collection of assets. We want to add the Standard Assets package, so select that and click on Import:
-
Figure 1.10 – Importing assets via the Package Manager
Important note
Your list of packages will most likely differ from mine. Unity contains many built-in packages, and any package added from the Unity Asset Store will also appear here.
Each time you import a package, you will be presented with an Import dialog. Here, you can specify which assets you want to add to your project. Leave all settings at their defaults, and click on Import:

Figure 1.11 – Choosing assets to import
Important note
Make sure you don't modify the folder structure of imported assets. Unity will only be able to determine whether an asset has changed if the project structure remains the same. For example, if you import a package that places a material in the Assets/Materials folder and you move that asset when you come to update the package, Unity will think the material is missing and re-add it to the project—resulting in two versions of the asset.
By default, Unity decompresses all files from the package into the current project, ready for use. These files are copies of the originals. So, any changes made to them will not affect or invalidate the originals, which Unity maintains internally in a .meta file. Every asset (including folders) has a corresponding meta file, which contains information on the import settings of the asset and should not be deleted or renamed unless you are also deleting or renaming the associated asset.
The files include models, sounds, textures, and more, and are listed in the Unity Editors project window:

Figure 1.12 – Browsing imported assets from the Project panel
The imported assets don't yet exist in our game scene or level. They don't appear in the game, and they won't do anything when the level begins! Rather, they're only added to the Project panel, which behaves like a library or repository of assets, from which we can pick and choose to build up a game when needed. To get more information about each asset, you can select the asset by clicking on it with the mouse, and asset-specific details will be shown on the right-hand side of the Unity Editor in the Inspector panel. Inspector is a property sheet editor that appears on the right-hand side of the interface. It is context-sensitive and always changes to display properties for the selected object, as shown in Figure 1.13:

Figure 1.13 – The Inspector window displays all the properties for the currently selected object
We've now created a Unity project and imported a large library of assets, in the form of a package, using the Package Manager. The package includes architectural meshes for walls, floors, ceilings, and stairs. This means that we're now ready to build our first level using these assets!