please help me regarding timer countdown

i want my countdown timer to execute do my condition everytime it meets the condition… here us my code…

var startTime = 30.0;
var timer: GameObject;
var intTime;

function Update()
{
//start of problem
//this condition is my problem… every time the time is <=10; i want my the time to a add 20 seconds. It works properly but only once… when the time added 20 seconds it will not repeat the condition…

timeTaken = startTime - Time.time;
if (timeTaken <= 10.0)
{

timeTaken += 20.0;
}

timer.guiText.text = FormatTime (timeTaken);

}
//end of problem

function FormatTime (time)

{
intTime = time;
var minutes : int = intTime / 60;
var seconds : int = intTime % 60;
var fraction : int = time * 10;
fraction = fraction % 10;

timeText = minutes.ToString () + “:”;
timeText = timeText + seconds.ToString ();
timeText += “:” + fraction.ToString ();
return timeText;
}


it already does :

if (timeTaken <= 10.0) 
{ 
    timeTaken += 20.0; 
}

sir i didn’t get it…

if (timeTaken <= 10.0) -> condition
{ 
    timeTaken += 20.0; -> action when condition is met.
}

yes sir… but it only repeat once…

no, it keeps repeating.

Here is a simple 20 second looping timer if you want to use it. It’s quite simple.

var delay:float = 20;
var tmrValue:float = 0;
private var curValue:float = 0;

function Update () 
{
	curValue += Time.deltaTime;
	if(curValue >= delay)
	{
		curValue -= delay;
		//Looping Code Here
	}
}

EDIT:

Your issue is using Time.time which is constantly growing from the start of the game. (gets the time the frame was started, not how long the frame took to process.)

thank you sir! :slight_smile: