Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with Unity 2018

You're reading from   Getting Started with Unity 2018 A Beginner's Guide to 2D and 3D game development with Unity

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788830102
Length 336 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dr. Edward Lavieri Jr. Dr. Edward Lavieri Jr.
Author Profile Icon Dr. Edward Lavieri Jr.
Dr. Edward Lavieri Jr.
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Downloading and Installing Unity FREE CHAPTER 2. The Unity Interface 3. Designing the Game 4. Creating Our Terrain 5. Lights, Cameras, and Shadows 6. Creating and Importing 3D Objects for Our Game 7. Implementing Our Player Character 8. Implementing Our Non-Player Characters 9. Adding a Heads-Up Display 10. Scripting Our Points System 11. Scripting Victory and Defeat 12. Adding Audio and Visual Effects to Our Game 13. Optimizing Our Game for Deployment 14. Virtual Reality 15. Other Books You May Enjoy

Implementing defeat


There are two game conditions in which the player can lose the game. The first condition is if there are no cucumbers left in the game. The second condition is if all three lives are gone. Let's look at each of these defeat conditions separately.

Scripting defeat based on no cucumbers remaining

Our CucumberManager script already keeps track of the number of cucumbers in the game, so we merely need to give that script's currentCucumberCount class variable the static modifier and then update our VictoryManager script. Here are the steps.

  1. Edit the CucumberManager script so the currentCucumberCount variable declaration is as follows:

      public static int currentCucumberCount;
  1. In the Awake() method, change currentCucumberCount = 0; to currentCucumberCount = 1;. This will help ensure the game does not think there are no cucumbers when the game starts.
  2. Add the following statement at the end of the Update() method, currentCucumberCount = cucumbers.Length;. This will keep the counter...
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
Banner background image