How to get a countdown timer

hi im trying to get a Countdown timer in javascript if possible i need the timer to countdown from 2mins when it reaches zero it resets the scene any ideas how i can do this ?

Make a float or double in your script that will keep track of the timer. Set it to 120 (60 sec * 2 minutes), then each Update() subtract Time.deltaTime from that. Check to see if timer <= 0. Once it is call the load scene function of your choice.

Duplicate Question : how to make time limit with javascript? - Questions & Answers - Unity Discussions


Yes, persevere oOoJaMz93oOo, you have to do your homework!

I wrote a little guide on timers for someone else, so here it is for you to read, absorb and learn from :

in response to : Ive looked at a few different ways of making a timer but there not making any sense to me, could you help me out?

I personally have seen 2 types of timer/counter. The first is with a ‘counter’ and a maximum value.

var counter : float = 0.0;
var counterMax : float = 5.0;

function Update()
{
    if ( counter > counterMax )
    {
       // do stuff
       // reset Timer
       counter = 0.0;
    }
	// increment timer over time
    counter += Time.deltaTime;
	
	// increment counter with an integer value (like counting frames)
	// counter ++; // like this, counter can be an integer
}

the other method is using Time.time itself, but it still need an increment value to work.

var counter : float = 0.0;
var counterDelay : float = 5.0;

function Update()
{
    if ( Time.time > counter )
    {
       // do stuff
       // reset Timer
       counter = Time.time + counterDelay;
    }
}