Hello all,
I have a timer set up and when it reaches zero the player has to restart the level. But with this code it restarts the level and promptly freezes. This is not desirable. I want to be able to continue playing and have my timer start again at its initial value.
Can somebody point me in the right direction?
Here is my code…
var startTime = 30.0;
var timeLeft : float;
function Update () {
//Time left before level is reset
timeLeft = startTime - Time.time;
//No such thing as negative time
timeLeft = Mathf.Max (0, timeLeft);
//Format time
guiText.text = FormatTime (timeLeft);
//When time is 0, restart level
if (timeLeft == 0) {
Application.LoadLevel ("waxenpith");
startTime = 30.0;
}
}
//Format time
//12(minutes):34(seconds).5(fraction)
var intTime : int;
var minutes : int;
var seconds : int;
var fraction : int;
function FormatTime (time) {
intTime = time;
minutes = intTime / 60;
seconds = intTime % 60;
fraction = time * 10;
fraction = fraction % 10;
//Build string according to format
//12(minutes):34(seconds).5(fraction)
timeText = minutes.ToString () + ":";
timeText = timeText + seconds.ToString ();
timeText += "." + fraction.ToString ();
return timeText;
}
Hugs and kisses,
cz2isq