Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unity Certified Programmer Exam Guide - Second Edition

You're reading from  Unity Certified Programmer Exam Guide - Second Edition

Product type Book
Published in May 2022
Publisher Packt
ISBN-13 9781803246215
Pages 766 pages
Edition 2nd Edition
Languages
Author (1):
Philip Walker Philip Walker
Profile icon Philip Walker

Table of Contents (17) Chapters

Preface 1. Chapter 1: Setting Up and Structuring Our Project 2. Chapter 2: Adding and Manipulating Objects 3. Chapter 3: Managing Scripts and Taking a Mock Test 4. Chapter 4: Applying Art, Animation, and Particles 5. Chapter 5: Creating a Shop Scene for Our Game 6. Chapter 6: Purchasing In-Game Items and Advertisements 7. Chapter 7: Creating a Game Loop and Mock Test 8. Chapter 8: Adding Custom Fonts and UI 9. Chapter 9: Creating a 2D Shop Interface and In-Game HUD 10. Chapter 10: Pausing the Game, Altering Sound, and a Mock Test 11. Chapter 11: Storing Data and Audio Mixer 12. Chapter 12: NavMesh, Timeline, and a Mock Test 13. Chapter 13: Effects, Testing, Performance, and Alt Controls 14. Chapter 14: Full Unity Programmer Mock Exam 15. Other Books You May Enjoy Appendix

Planning and creating our enemy

We have a player that moves, shoots, and takes damage; we can now start looking into creating an enemy that shares these attributes.

To remind ourselves of the genre we are making, our game carries the same traits as classic arcade shooters such as Konami's Gradius, Capcom's UN Squadron, and Irem's R-Type (https://github.com/retrophil/Unity-Certified-Programmer-Exam-Guide-2nd-Edition/blob/main/Reference/shootEmUps.png). Typically, with these types of games, the player is swarmed by enemies coming from the right of the screen and exiting to the left.

In this section, we will be repeating similar aspects of the PlayerSpawner and Player scripts. The EnemySpawner script needs to be tweaked so that it will instantiate a given number of enemy ships at a certain rate.

The Enemy game objects will be moving on their own, so there needs to be some extra code applied to their behavior. Before we go into creating our first enemy script, let's look at a part of our game framework and note that the layout is basically the same as the player's side of the game framework:

Figure 2.46 – EnemySpawner and Enemy UML

Figure 2.45 – EnemySpawner and Enemy UML

Before we jump into the EnemySpawner script, let's do the same housekeeping we did for our player game objects, namely creating an empty game object and storing all game objects relating to it in that one game object. The reason we did this is to remove the clutter in the Hierarchy window, so let's do the same for our enemies:

  1. Right-click in the Hierarchy window's open space.
  2. A drop-down list will appear; select Create Empty.
  3. Name the game object _Enemies.

Let's move on to our enemy scripts.

You have been reading a chapter from
Unity Certified Programmer Exam Guide - Second Edition
Published in: May 2022 Publisher: Packt ISBN-13: 9781803246215
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 $15.99/month. Cancel anytime}