How to stop and reset the count down timer?

Hi guys,

I set a count down timer, and it doesn’t what I want to count down. However, when the timeRemaining < 0, it does stop counting as 0:00, but it never been reset. Also, if I completed the game earlier, when I restart and reload the game, it still shows the time I left. I already tried to switch the Time.time to Time.deltaTime, and tried to use a reset function, but it seems doesn’t have any difference. I’m really new in unity, and I searched and tried the way as many as I can, but I still don’t know how to make it happen. Can anyone help me with that? Thanks!

Script as below:

var startTime: float;

var timeRemaining: float;

function start() {

startTime = 300.0;

}

function Update() {

Countdown();

}

function Countdown() {

if(timeRemaining > 0) {

    timeRemaining = startTime - Time.time;

    ShowTime();

}

else if(timeRemaining < 0) {

	resetTimer();
}

}

function ShowTime() {

var minutes: int;

var seconds: int;

var timeString: String;

minutes = timeRemaining/60;

seconds = timeRemaining%60;

timeString = minutes.ToString() + ":" + seconds.ToString("D2");

guiText.text = timeString;

}

function resetTimer() {

startTime = 300.0;

}

Hi i had similar problem. Tell me if this solves your problem as im new to unity too.

var startTime: float;
var timeRemaining: float;
function Start(){
startTime = 5.0;
}
function Update(){
Countdown();
}
function Countdown(){
timeRemaining = startTime - Time.timeSinceLevelLoad ;
ShowTime();
if(timeRemaining < 0)
{
timeRemaining = 0;
TimeIsUp();
ShowTime();
Debug.Log("Time Remaining = "+ timeRemaining);
}
}
function ShowTime(){
var minutes: int;
var seconds: int;
var TimeString: String;
minutes = timeRemaining/60;
seconds = timeRemaining%60;
timeString = minutes.ToString() + ":" + seconds.ToString("D2");
guiText.text = timeString;
}
function TimeIsUp(){
Application.LoadLevel(3);
}

To make it simple i did use Time.timeSinceLevelLoad - This is the time in seconds since the last level has been loaded.