Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Unity 2020 Game Development

You're reading from   Hands-On Unity 2020 Game Development Build, customize, and optimize professional games using Unity 2020 and C#

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781838642006
Length 580 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nicolas Alejandro Borromeo Nicolas Alejandro Borromeo
Author Profile Icon Nicolas Alejandro Borromeo
Nicolas Alejandro Borromeo
Arrow right icon
View More author details
Toc

Table of Contents (24) Chapters Close

Preface 1. Chapter 1: Designing a Game from Scratch 2. Chapter 2: Setting Up Unity FREE CHAPTER 3. Chapter 3: Working with Scenes and GameObjects 4. Chapter 4: Grayboxing with Terrain and ProBuilder 5. Chapter 5: Importing and Integrating Assets 6. Chapter 6: Materials and Effects with URP and Shader Graph 7. Chapter 7: Visual Effects with Particle Systems and VFX Graph 8. Chapter 8: Lighting Using the Universal Render Pipeline 9. Chapter 9: Fullscreen Effects with postprocessing 10. Chapter 10: Sound and Music Integration 11. Chapter 11: User Interface Design 12. Chapter 12: Creating Animations with Animator, Cinemachine, and Timeline 13. Chapter 13: Introduction to Unity Scripting with C# 14. Chapter 14: Implementing Movement and Spawning 15. Chapter 15: Physics Collisions and Health System 16. Chapter 16: Win and Lose Conditions 17. Chapter 17: Scripting the UI, Sounds, and Graphics 18. Chapter 18: Implementing Game AI for Building Enemies 19. Chapter 19: Scene Performance Optimization 20. Chapter 20: Building the Project 21. Chapter 21: Finishing Touches 22. Chapter 22: Augmented Reality in Unity 23. Other Books You May Enjoy

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 will have a starting number of 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 our base environment, which consists of large metallic floor tiles, walls, doors where the enemies will be spawning, and our base building at the bottom part of the screen, 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.4 – Base layout

Figure 1.4 – 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 as 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: Start Hero 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 in a gentle way.

Starting condition

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

  • Number and placement of Enemies' Spawn Points (doors)
  • Number of bullets held by the Hero
  • Placement of the Base

Let's look at each of these starting conditions:

  • The first starting condition is where to spawn Enemies. As you saw in our earlier mock-up, there will be several possible spawn points in the game (the doors). We will write a script to spawn waves of the enemies in random spots each time. Each wave will increase the number of enemies to increase the difficulty.
  • The number of bullets held by the player must be carefully thought through. It needs to be big enough to defeat an enemy before they run out.
  • Our third and final starting condition is the base placement. As you can see from the preceding screenshot, 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. Let's remember them—they are as follows:

  • Remaining Waves
  • Base Health
  • Player Health

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.5 – End-of-game conditions

Figure 1.5 – End-of-game conditions

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

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 or we could also take away points each time an Enemy damages 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 any way to make informed decisions about those. 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 and 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.

Information Box:

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.6 – UI layout

Figure 1.6 – 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 visually 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.
  • Remaining Waves/Enemies: Info 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. It's of sufficient size to let the player notice when the base is being attacked, and take action in that case.

Finally, we have a fully fledged game 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 it's never too soon to implement: balancing the game.

lock icon The rest of the chapter is locked
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