system
1
How do I reset the time after the game fail? The time just keeps decreasing in my game even after the game over scene is played out and it restarts back to the main scene.
This is my script attached to the GUI for time:
#pragma strict
private var startTime;
var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
var countDownSeconds : int;
function Awake() {
startTime = countDownSeconds;
}
function Update ()
{
guiText.text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds);
}
function OnGUI () {
var startTime: float;
var guiTime: float = Time.time - startTime;
restSeconds = countDownSeconds - (guiTime);
if (restSeconds == 60) {
print ("One Minute Left");
}
if (restSeconds == 0) {
print ("Time is Over");
LevelFail();
}
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = roundedRestSeconds / 60;
}
function LevelFail()
{
Application.LoadLevel("GameOver");
startTime = 240;
}
My countDownSeconds is set to 240 in the inspector. Thank you! 
You are counting down using Time.time, instead of detracting Time.deltaTime every frame. The problem here is that Time.time is absolute- which means that no amount of level loading and resetting will set it back to zero: just like in real life, time that is lost can never be recovered.
Instead, you should put a countdown float at the top and decrease it by Time.deltaTime inside the Update function, then base all of your GUI stuff off it. Another thing, by redefining startTime at the top of OnGUI, you are actually hiding the startTime var elsewhere in your program, which I don’t think you really want to do.