I have a countdown timer which, once it reaches 0:00, it executes and Application.LoadLevel and loads a different scene. The only problem here, is that if I go back to the previous scene, the timer is still going. It doesn’t stop, it keeps going into the negatives. How can I stop it once it reaches 0 and reset it if the scene gets reloaded??
var startTime : int;
var restSeconds : int;
var roundedRestSeconds : int;
var displaySeconds : int;
var displayMinutes : int;
var countDown : int;
function Update () {
//make sure that your time is based on when this script was first called
//instead of when your game started
startTime = 12;
var guiTime = Time.time - startTime;
restSeconds = countDown - (guiTime);
//display messages or whatever here -->do stuff based on your timer
if (restSeconds == 60) {
print ("One Minute Left");
}
if (restSeconds == 0) {
print ("Time is Over");
MouseFollow.playerScore = 0;
Application.LoadLevel(2);
}
//display the timer
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
guiText.text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
//GUI.Label (Rect (350, 25, 100, 30), text);
}
Thanks.