September 2011
Beginner
408 pages
9h 52m
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 ...Read now
Unlock full access