Hi, I am using javascript trying to get my game over screen to load once my timer has reached zero, at the moment when I press play it loads the other level straight away, can someone see where I’m going wrong please? scripts below:
this is my timer code (named “countdownTimer”):
var seconds = 60;
private var textMesh : TextMesh;
function Start () {
textMesh = GameObject.Find ("Timer").GetComponent(TextMesh);
textMesh.text = seconds.ToString();
InvokeRepeating ("Countdown", 1.0, 1.0);
}
function Countdown () {
if (--seconds == 0) CancelInvoke ("Countdown");
textMesh.text = seconds.ToString();
}
this is the code to check if timer has reached zero(named “highscore_set”):
#pragma strict
var countdownTimer : countdownTimer;
function Update(){
if (countdownTimer.seconds ==0);
GameOver();
}
function GameOver () {
if(Scorecounter.Counter > PlayerPrefs.GetInt("highscore"))
{
PlayerPrefs.SetInt("highscore", Scorecounter.Counter);
}
Application.LoadLevel(3);
}
I have the gameobject with the countdownTimer script added to the inspector slot on highscore_set script.