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 2021 Game Development

You're reading from   Hands-On Unity 2021 Game Development Create, customize, and optimize your own professional games from scratch with Unity 2021

Arrow left icon
Product type Paperback
Published in Aug 2021
Publisher Packt
ISBN-13 9781801071482
Length 710 pages
Edition 2nd 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 (29) Chapters Close

Preface 1. Section 1 – Our First Level
2. Chapter 1: Designing a Game from Scratch FREE CHAPTER 3. Chapter 2: Setting Up Unity 4. Chapter 3: Working with Scenes and Game Objects 5. Chapter 4: Grayboxing with Terrain and ProBuilder 6. Chapter 5: Importing and Integrating Assets 7. Section 2 – Improving Graphics and Sound
8. Chapter 6: Materials and Effects with URP and Shader Graph 9. Chapter 7: Visual Effects with Particle Systems and Visual Effect Graph 10. Chapter 8: Lighting Using the Universal Render Pipeline 11. Chapter 9: Fullscreen Effects with Postprocessing 12. Chapter 10: Sound and Music Integration 13. Chapter 11: User Interface Design 14. Chapter 12: Creating a UI with the UI Toolkit 15. Chapter 13: Creating Animations with Animator, Cinemachine, and Timeline 16. Section 3 – Scripting Level Interactivity with C#
17. Chapter 14: Introduction to C# and Visual Scripting 18. Chapter 15: Implementing Movement and Spawning 19. Chapter 16: Physics Collisions and Health System 20. Chapter 17: Win and Lose Condition 21. Chapter 18: Scripting the UI, Sounds, and Graphics 22. Chapter 19: Implementing Game AI for Building Enemies 23. Chapter 20: Scene Performance Optimization 24. Section 4 – Releasing Your Game
25. Chapter 21: Building the Project 26. Chapter 22: Finishing Touches 27. Chapter 23: Augmented Reality in Unity 28. 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 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.

You have been reading a chapter from
Hands-On Unity 2021 Game Development - Second Edition
Published in: Aug 2021
Publisher: Packt
ISBN-13: 9781801071482
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 €18.99/month. Cancel anytime