September 2010
Beginner
384 pages
8h 49m
English
The easiest way to figure out if the player has lost is to check the transform.position.y value of the heart. If the heart has fallen through the floor, the player obviously isn't bouncing it on the tray any longer.
function OnCollisionEnter(col : Collision) {
if(col.gameObject.tag == "tray") {
//Debug.Log("yes! hit tray!");
if (!velocityWasStored) {
storedVelocity = rigidbody.velocity;
velocityWasStored = true;
}
if(rigidbody.velocity.y > 1) {
numHits ++;
}
rigidbody.velocity.y = storedVelocity.y;
}
Update function:function Update() { var str:String = ""; if(!hasLost){ str = numHits.ToString(); ...Read now
Unlock full access