I am making a game. There is a main menu, first level and gameover scene. When you lose all your lives the gameover screen shows up. After a certain amount of time the gameover screen changes to the main menu. From the main menu the first level can be accessed. If I play the game, the transitions all work but if i go to the first level after losing all lives and going back to the main menu the gameover scene starts playing. How can I change the game so that it resets the lives after you lose?
Health script:
var health1 : Texture2D; //one live left
var health2 : Texture2D; //two lives left var health3 : Texture2D; //full health
static var LIVES = 3;
function Update () { switch(LIVES) { case 3: guiTexture.texture = health3; break;
case 2:
guiTexture.texture = health2;
break;
case 1:
guiTexture.texture = health1;
break;
case 0:
Application.LoadLevel (2);
break;
}
}
Die script:
private var dead = false;
private var timeSinceLastCollision = 0;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "Finish" && timeSinceLastCollision <= 0) { dead = true; //subtract life here Health.LIVES -=1; timeSinceLastCollision = 5; //Wait at least 5 seconds between collisions } timeSinceLastCollision -= Time.deltaTime; }
function LateUpdate() { if(dead) { transform.position = Vector3(2,6.5,2); gameObject.Find("Main Camera").transform.position = Vector3(0,0,0); dead = false; } }