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.
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;
Save the script and return to Unity.
Select the Heart in the Hierarchy panel.
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.Add the following code to the
Update
function:function Update() { var str:String = ""; if(!hasLost){ str = numHits.ToString(); } else { str = "Hits:" + numHits.ToString() + "\nYour best:" + bestScore; if(bestScore > lastBest) str += "\nNEW...