Scripting defeat for no lives remaining

We will use the CucumberManManager script to keep track of the number of lives the Cucumber Man has remaining. Edit that script and make the following changes:

  1. Add the public static int livesRemaining; class variable. We will use this variable to track the number of remaining lives.
  2. Add the public Animator anim; class variable. We will use this to play the Cucumber Man's death animation.
  3. Add the livesRemaining = 3; statement to the bottom of the Awake() method.
  1. Add the following if statement block to the bottom of the Update() method:
         if (livesRemaining == 0) {             anim = GetComponent<Animator> ();             anim.Play ("CM_Die");          } 

As you can see in the changes to our Update() method, we are simply checking ...

Get Getting Started with Unity 2018 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.