Why is the timer increasing after every reset?

I’m trying to get a simple countdown timer to reset after a given time.
The first time it runs fine (starts at 12 and resets to 12), the second time it resets to 24, the third time to 48 and so on…

#pragma strict

var timer : float = 12.0;
var ionCannonDeployed : AudioClip;

function Update ()
{
	timer -= Time.deltaTime;
	
	if(timer <= 0)
	{
		Reset();
	}
	
	else
	
	if(timer <= 6)
	{
		//audio.PlayOneShot(ionCannonDeployed);
		//And do other uber cool stuff
	}
}

function OnGUI()
{
	GUI.Box(new Rect( 100, 10, 140, 20), "" + timer.ToString("0"));
}

function Reset()
{
	timer = Time.time;
} 

What am I missing guys ???

You have to use timer = 12; inside your Reset. Time.time counts the time since the game was started. So if you you are resetting your timer after 12 seconds, Time.time will equal 12 and if you are resetting the time for the second time, Time.time will equal 24. (12 seconds + 12 seconds).

I hope it makes sense!

So:

C#

void Reset()
 {
   timer = 12.0f;
 } 

JavaScript

function Reset()
 {
   timer = 12.0;
 }

function Reset()
{
timer = 12.0;
}

yep, thanks guys. works perfectly now

:slight_smile: