[SOLVED]Cant reset the timer if my main character dies

Hey,
Im trying to figure out how can i reset the time when the player dies or runs out of time. I use Application.loadedLevel function in the Die()(see code). Everytime i use it,it starts the level over but it keeps looping the stage over and over again. I think its coming from the timer since it is not updating with the rest of the app. How can i fix this? Everything else updates when the player dies…Health,kills,etc.
Heres the code:

var countdown : GUIText;
var startTime : float = 180.0;
var timeLeft : float ;

function Update(){
 
      timeLeft = startTime - Time.time; 
	  
      timeLeft = Mathf.Max(0, timeLeft); 
 countdown.text = ReadableTime(timeLeft);
if(timeLeft == 0){
Die();
}
}

function Die () {
	
	// Disable all script behaviours (Essentially deactivating player control)
	var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
	for (var b in coms) {
		var p : MonoBehaviour = b as MonoBehaviour;
		if (p)
			p.enabled = false;
	}

	LevelLoadFade1.FadeAndLoadLevel(Application.loadedLevel, Color.red, 2.0);
}

function ReadableTime(fl_time_fp : float) { 
   var i_minutes : int; 
   var i_seconds : int; 
   var i_time : int; 
   var s_timetext : String; 
   i_time = fl_time_fp; 
   i_minutes = i_time / 60; 
   i_seconds = i_time % 60; 
   s_timetext = i_minutes.ToString() + ":"; 
   s_timetext = s_timetext + i_seconds.ToString(); 
   
return s_timetext; 
}

[/code][/b][/i]

hey,

Im not good in coding JS, but 2 lines seem to make no sense to me:

var startTime : float = 180.0;

function Update(){ 
if (startTime) ...

and

function Die () { 
   if (Die) ...

you might want to compare startTime with some value and “Die” could be declared e.g as a boolean.

Anyway, if it does make sense JS wisely, you are missing brackets after “if (Die)”.


oxl

Ok i figured it out,i had to use the timeSinceLevelLoad variable. Thanks anyways!