Book Image

Getting Started with Unity 2018 - Third Edition

By : Dr. Edward Lavieri
Book Image

Getting Started with Unity 2018 - Third Edition

By: Dr. Edward Lavieri

Overview of this book

The Unity game engine has revolutionized the gaming industry with its complete set of intuitive tools and rapid workflows, which can be used to create interactive 3D content. With Unity, you can scaffold your way from the basics and make make stunning interactive games. This book will guide you through the entire process of creating a 3D game, from downloading the Unity game engine to publishing your game. It not only gives you a strong foundation, but puts you on the path to game development. Beginning with an overview of the Unity engine and its interface, you will walk through the process of creating a game environment and learn how to use built-in assets, as well as assets created with third-party 3D modeling tools such as Blender. Moving on, you will create custom scripts to control non-player character behaviors and gameplay. You will master exciting concepts such as Heads-Up-Displays, mini-maps, game navigation, sound effects, and lighting effects. Next, you’ll learn how to create your first VR experience, right from setting up the project to image effects. You'll be familiarized with all the tools that Unity has to offer to create your own immersive VR experiences. Each section is a stepping stone toward the completion of the final game. By the end of the book, you'll have learned advanced topics such as cross-platform considerations which enable your games to run on multiple platforms.
Table of Contents (21 chapters)
Title Page
Packt Upsell

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...