O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. Drag the Bounce Count GUIText Game Object from the Hierarchy panel into the GUIText slot of the heart in the Inspector panel (or choose it from the drop-down list). Now, whenever we refer to hitCount in our script, we'll be talking about our GUIText Game Object.
  5. Add the following code to the Update function:
    function Update() { Ticker Taker ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required