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]