Time for action – keeping track of the bounces

Let's introduce a few more variables to record how many times the player has bounced the heart.

  1. Change the code to add these three variables at the top:
    var hitCount:GUIText;
    var numHits:int = 0;
    var hasLost:boolean = false;
    var velocityWasStored = false;
    var storedVelocity : Vector3;
  2. Save the script and return to Unity.
  3. Select the Heart in the Hierarchy panel.
  4. We've created a variable (bucket) to hold a GUIText object. Drag the Bounce Count GUIText GameObject from the Hierarchy panel into the GUIText slot of the heart in the Inspector panel (or choose it from the pop-up menu). Now, whenever we refer to hitCount in our script, we'll be talking about our GUIText GameObject.
  5. Add the following code to the ...

Get Unity 4.x Game Development by Example Beginner's Guide 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.