Book Image

Hands-On Unity 2021 Game Development - Second Edition

By : Nicolas Alejandro Borromeo
Book Image

Hands-On Unity 2021 Game Development - Second Edition

By: Nicolas Alejandro Borromeo

Overview of this book

Learning how to use Unity is the quickest way to creating a full game, but that’s not all you can do with this simple, yet comprehensive suite of video game development tools – Unity is just as useful for creating AR/VR experiences, complex simulations, real-time realistic rendering, films, and practical games for training and education. Hands-On Unity 2021 Game Development outlines a practical journey to creating your first full game from the ground up, building it step-by-step and applying your knowledge as you progress. Complete with hands-on tutorials and projects, this easy-to-follow guide will teach you how to develop the game using several Unity tools. As you advance, you will learn how to use the Unity engine, create simple scripts using C#, integrate graphics, sound, and animations, and manipulate physics to create interesting mechanics for your game. You’ll be able to apply all the knowledge that you gain to a real-world game. Later chapters will show you how to code a simple AI agent to challenge the user and use profiling tools to ensure that the code runs efficiently. Finally, you'll work with Unity's AR tools to create AR experiences for 3D apps and games. By the end of this Unity book, you will have created a complete game and built a solid foundation in using a wide variety of Unity tools.
Table of Contents (29 chapters)
1
Section 1 – Our First Level
7
Section 2 – Improving Graphics and Sound
16
Section 3 – Scripting Level Interactivity with C#
24
Section 4 – Releasing Your Game

Gameplay

The game will start with the player in the center of the game world. The Hero, controlled by the player, will need to defend the Base from the Enemies. To fend off the Enemies, the Hero can shoot bullets. The goal is to defeat all the Enemies before the Base is completely destroyed by them.

Let's look at how we will make all this happen. The following gameplay components are covered in this section:

  • Game-world layout
  • Starting condition
  • Ending condition
  • Point system
  • Heads-Up Display (HUD)

We will cover each of the preceding components and discuss how they change the game experience. Let's start by talking about how the game world will be designed.

Game-world layout

We will create a base environment that consists of large metallic floor tiles, walls, and doors where the enemies will spawn. The base building will be located at the opposite end of the Enemies' Spawn positions (the Doors in the following figure), where the enemies need to reach to start attacking it.

Here is a mock-up of the shape our game world will take:

Figure 1.5 – Base layout

Figure 1.5 – Base layout

There are four basic things illustrated in the preceding mock-up, listed as follows:

  • Wall: Impenetrable barriers that prevent the player from going outside the play area.
  • Door: Impenetrable, like the walls, but will also serve as the Spawn Position of the Enemies. The Enemies will spawn behind them and can penetrate them to enter our Base Area.
  • Player Start: This is the Hero's start position.
  • Base Building: Our Base. The enemies must be close enough to attack it.

With our base-level design finished, let's discuss how the player will enter that world.

Starting condition

When our game is first launched, we will have several starting conditions set. Here is a list of those conditions:

  • The number and placement of Enemies' Spawn Points: As you saw in our earlier mock-up, there will be several possible spawn points in the game (the doors).
  • The number of Waves, the number of Enemies in each Wave, and how often the enemies will spawn: We will write a script to spawn waves of enemies, which will be used for each wave.
  • Our final starting condition is the base placement: As you can see from the preceding figure, this is placed on the opposite side of the doors—so, the enemy must traverse the whole empty space between them, giving the player a chance to attack them.

We have defined the enemy spawning rules and how the player can play the game. Now, let's talk about how the game will end, looking at the exact implementation of this.

Ending condition

So far, we have established that we will track several components in the game. They are as follows:

  • Remaining Waves: A wave is considered finished when all enemies in it die.
  • Base Health: Damaged by the enemies.
  • Player Health: Also damaged by the enemies.

Based on what we decided earlier regarding the end-of-game condition, we can apply the following mathematical checks to determine whether the game has ended and what the outcome is. Each end-of-game condition is listed in the following table, along with the outcome:

Figure 1.6 – End-of-game conditions

Figure 1.6 – End-of-game conditions

In order to implement these three end-of-game conditions, we know we must track the number of waves, player health, and base health.

Now that we have a full game, let's think about how we can make it more rewarding, by implementing a classic point system.

Point system

Since we are tracking key information that involves numbers, it makes it easy for us to implement a point system. We could, for example, give the player 50 points each time an Enemy is exterminated, and we could also take away points each time an Enemy causes damage to the base. In our case, we will settle with just giving points when Enemies are killed, but you can feel free to expand this area if you want to.

Now, we have several systems that the player needs to be aware of, but right now, the player hasn't got any way to make informed decisions about those systems. So, let's see how we can improve that, using an HUD.

HUD

We have decided to keep track of information during gameplay that has value beyond calculating points at the end of the game. The player will want to see this information as it tends to provide motivation and adds to the fun of the game. So, we will create an HUD for the player, and dynamically update the data in the game.

Important note:

An HUD is a visual layer of information that is always present on the screen.

Here is a mock-up of what our HUD will look like in our Super Shooter game:

Figure 1.7 – UI layout

Figure 1.7 – UI layout

As you can see, there are several components to our HUD, as follows:

  • Hero Health: A classic health bar that allows us to see the amount of life left. We choose a bar instead of a number because it is easier to see in the middle of an intense fight, instead of reading a number.
  • Hero Avatar: An image next to the health bar just to show our Hero's face.
  • Score: The number of points we have gathered.
  • Bullets: The number of bullets remaining. The player must check this number frequently to avoid running out of bullets, as they are limited. Anyway, at the end of the book, you will be more than capable of creating a bullet-drop system if you want to.
  • Remaining Waves / Remaining Enemies: Information about the current state of the wave and game, just to let the player know when the game is going to end, putting some pressure on them in the process.
  • Base Health: Another important piece of information so the player can see the health of the Base. It's of a sufficient size to let the player notice when the base is being attacked and take action in that case.

Finally, we have a simple, yet fully fledged starter game design with lots of rules and specifications about how it will behave, and we can start creating our game right now. However, there's a good practice that is never too soon to implement: balancing the game's difficulty.