Chapter 1: Exploring the Fundamentals of Unity
Unity is a game engine that works with your existing asset pipeline (such as 3D modeling software) and can be used to compile video games that work seamlessly across multiple platforms and devices, including Windows, Mac, Linux, Android, and iOS. Using Unity, developers import ready-made assets (such as music, textures, and 3D models), and assemble them into a coherent whole, forming a game world that works according to a unified logic. This book focuses on developing games in Unity 2020 — taking you step by step through how to create increasingly complex projects.
This chapter starts the first project on our list, which will be a fun collection game. By the end of the next chapter, you'll have pieced together a simple but complete game. As part of the process, you'll become familiar with the fundamentals of developing in Unity, including the following:
- New features in Unity 2020
- Creating new projects using Unity Hub
- How to navigate the Unity editor
- Unity project structure
- Importing assets using the Package Manager
- Using the Unity editor to create a level
- Creating optimized lighting effects
- How to playtest the game
Using the information in this chapter, you will gain an understanding of how to create new projects from scratch, navigate the Unity editor, and import assets, information that will be invaluable for years to come as you develop your own projects in Unity.
Remember, it doesn't matter if you've never used Unity before. We'll go through everything that is required step by step, starting with the new features found in Unity 2020.
Technical requirements
This book is about Unity and developing games in that engine. The basics of programming as a subject is, however, beyond the scope of this book. So, I'll assume that you already have a working knowledge of coding generally but have not coded in Unity before.
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Unity-2020-By-Example.
Once downloaded, you can find the CollectionGame project in the Chapter01/End folder.
Exploring new features in Unity 2020
Before we start our first project, let's take a moment to look at the new features introduced since the previous edition of this book. We'll cover all of these, and much more!
Starting with Unity Hub, while not technically part of Unity 2020 (it is a separate application), it makes it easy to manage multiple Unity projects and versions. I will guide you through creating a new project using Unity Hub in this chapter. Once an empty project has been created, we will import assets using the new Package Manager — an easy way to manage a project's assets (more on this shortly).
In the world of 2D, a new tool called Sprite Shape will help us create more dynamic and flexible environments from within the Unity editor. Whether 2D or 3D, Artificial Intelligence (AI) is an ever-evolving field, and not to be left behind, Unity has introduced a new machine learning toolkit called ml-agents. This is an exciting new way to create intelligent agents (any dynamic non-playable character) in a game. Rather than defining exactly how an agent should act in every situation, we can provide the tools for the agent to learn how best to achieve their goals, whatever they may be.
It's an exciting time for Augmented Reality (AR), with the inclusion of ARFoundation in Unity, an AR toolkit, which we will use to blend reality and gaming. Lastly, we'll take a look at state of the art and investigate how we can optimize our games by using DOTs, a multi-threaded data-oriented technology stack. Don't worry if that sounds scary; it will all become clear as we progress through the book.
Now that we have an understanding of the some of the new topics covered in this book, let's design the first game we will implement in Unity 2020.
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...