I have 2 scenes in my game. the playing level and the ‘you have failed’ level. I have a button on my fail level to go back to the playing level with a simple application.loadlevel script attached, however my timer is not reset so the playing screen just flashes up. Here is my timer code, i have looked at other forums and I dont understand why it doesnt work. thankyou for any help
var startTime = 30.0;
var timeLeft : float;
function Start ()
{
startTime = Time.time;
startTime = 30.0;
}
function Update () {
//Time left
timeLeft = startTime - Time.time;
//Time cannot go below zero
timeLeft = Mathf.Max (0, timeLeft);
//Format time
guiText.text = FormatTime (timeLeft);
//When time is 0, restart level
if (timeLeft == 0) {
Application.LoadLevel ("Level fail");
}
}
//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;
}