When I reload a scene, my timer doesn't reset.

This is the code I’m using to reload the scene

function Update () 
{
	if(Input.GetButtonUp("F"))
	{
	Application.LoadLevel("Disco strobe physics");
	}

When I hit “f” the scene loads with out trouble, but my GUI Timer doesn’t restart. If someone could tell me why/how to fix this that would be cool (I’m a novice as a side note, so take that into consideration).

I should probably include the timer script…

var isPaused : boolean = false; 
var startTime : float; //(in seconds) 
var timeRemaining : float; //(in seconds) 

function Start() 
{ 
	startTime = 60.0;
	Debug.Log("STARTED");
}

function Update() 
{ 
	if (!isPaused) 
	{
	 DoCountdown(); 
	}
}

function DoCountdown() 
{ 
	timeRemaining = startTime - Time.time;
	ShowTime () ;
	
	if (timeRemaining < 0) 
	{
	timeRemaining = 0; 
	isPaused = true; 
	TimeIsUp() ;
	}
}

function PauseClock() 
{
	isPaused = true;
}

function UnpauseClock() 
{
	isPaused = false;
}

function ShowTime() 
{
	var minutes : int; 
	var seconds : int; 
	var timeStr : String;
	minutes = timeRemaining/60;
	seconds = timeRemaining % 60;
	timeStr = minutes.ToString() + ":";
	timeStr += seconds.ToString("D2");
	guiText.text = timeStr; //display the time to the GUI
}

function TimeIsUp() 
{ 
	guiText.text = ("Time is up!");
}

Thanks in advance :slight_smile:

This is because Time.time is ‘the time in seconds since the start of the game’. Which doesn’t reset when you load a new level. You probably want to use Time.timeSinceLevelLoad instead.

Another way would be to use Time.deltaTime instead. Sinse this would make your Timer start when you instantiate the timer, rather then when you Load a level (at this moment you instantiate your timer at level load probably, but in case you change that in the future). (In this example you should set startTime in the inspector and only change these 2 functions)

function Start() 
 { 
     timeRemaining = startTime;
     Debug.Log("STARTED");
 }
 
 function DoCountdown() 
 { 
     timeRemaining -= Time.deltaTime;
     ShowTime () ;
     
     if (timeRemaining < 0) 
     {
     timeRemaining = 0; 
     isPaused = true; 
     TimeIsUp() ;
     }
 }