In this book, you’ll learn how to build 3D games using Unity - one of the most popular cross-platform game engines available today.
The book will first describe the most commonly used features of the Unity Editor and the Unity Hub.
It’ll then go on to describe how you build three separate, but related, games that collectively cover the most important aspects of game development. These include scene creation, detecting and managing collisions, user interface design and building, scripting, navigation, camera control, object pooling and animation.
The book also describes some of the best practices you should use to get the best out of Unity, and how to make your games run in the most efficient way, enabling you to focus on the fun part: making a great game that your players will enjoy!
Before You Begin
This section tells you a few things you need to know before you get started, such as what hardware and software you’ll need to get the most out of this book, where to find the project files for this book, and more.
Unity provides two applications to help you manage your game assets: the Unity Hub and the Unity Editor. This section will introduce you to both and show you how to start building your first game.
You’ll learn all about the Unity Editor’s user interface and gain a solid understanding of how everything is organized. Then, you’ll learn about GameObjects and Prefabs. You’ll go on to write some basic C# scripts to enhance the gameplay and add some interactivity to your first game: a very strange weapon-manufacturing machine!
In this chapter, you'll install the Unity Hub and set up your Unity Editor. You'll then use the Unity Starter Project content to create your first project. You'll take a tour through the features of the Unity Editor and conclude by making your first build.
It's time to start to create your first playable project from the ground up! In this game, you’ll construct forks and skewers using an "ammunition machine".
While creating the game, you'll learn all about GameObjects, the Unity building blocks that can represent just about anything from lights and scenery to NPCs, and Prefabs, which act as GameObject templates.
In this chapter you'll learn about C# and the best code editors to use with Unity. You'll also write your first scripts to control the behavior of GameObjects to make your game come to life.
Section II: Now You're Building With Components
Cameras, lights, sound, action! This section introduces you to a new game, where you’ll learn how to build cameras, lights, sound and interactivity! These are essential elements for any game because they make games compelling and fun to play.
You’ll also learn how to add a user interface and build a dialogue system to allow players to talk to your game’s avatars. The project in this section is set in a dining hall, so head on down there right away and you’ll meet some very strange characters indeed!
This is where you learn how to build a scene in your game. Just like a movie, scenes in Unity require cameras, sound and lights, so you'll add those first. You'll then go on to learn how to add avatars to make things even more realistic and interesting.
This chapter introduces you to Unity's input system to allow players to move your characters around. It will go on to cover Unity's physics system to stop objects passing through each other or falling through the floor!
This chapter introduces the concept of Scriptable Objects. These allow you to store data independent of your GameObjects. Here, you'll use them with a dialogue user interface that'll allow your avatar to 'talk' to other characters in your game.
Section III: Smart Enemies & the Bigger Picture
Your player shouldn’t be the only smart character in a game. In this section, you learn how to use the power of Unity to automatically control enemies to make your game a challenge. You’ll discover how to define where your enemies can roam and how to get them to attack!
You’ll also see how to control multiple cameras so the player doesn’t miss seeing a thing. Finally, learn how to reuse weapons and enemies once they’ve been expended so you can reduce the resources your game requires.
The game in this section takes place in an arena. Hurry! There’s a battle about to begin!
This chapter sets up the basic rules of a new tank game where you'll battle waves of Veggie Warriors! In addition to building the scene and the enemies' Prefabs, you'll be introduced to NavMeshes and Nav Mesh Agents. Together, these allow your main character to move around with a point-and-click interaction and provide the enemies with basic AI navigation to attack!
The Cinemachine package is a complete solution to manage multiple cameras and complex camera behaviors. Learn about the CinemachineBrain and how it can be used to transition between Virtual Cameras, or vcams, using Blends.
This chapter introduces the concepts of asynchronous programming and object pooling. You'll use these techniques to reduce resource usage and improve the performance of your game by removing and reusing GameObjects in a timely manner.
Section IV: Cooking Up Animations
Animation adds so much more interest and fun to games, and Unity has a wealth of tools and techniques to help you add the right effects. This section first introduces tween animations - an effective way to get objects to move from one place to another. It then goes on to cover more advanced animation principles that allow your characters to animate in different ways while in different states.
You’ll then look at using scriptable objects as data containers to make more efficient use of memory and increase your game’s responsiveness.
The action in this section takes place in the kitchen, where Chef is cooking up some interesting dishes…
In this chapter, you'll learn all about the Animator component. This allows you to control how different animations interact with each other, allowing you to add movement to your characters while they do different actions. You'll also learn how to control the state of animations from your scripts.