- Home /
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 ???
Answer by Pitomator · Jan 02, 2015 at 05:10 PM
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;
}
Your answer
Follow this Question
Related Questions
Help - I need a simple reset/teleport function for my ArchViz project! 1 Answer
How to reset Time.time ? 1 Answer
Starting/Triggering events based on hover time 0 Answers
Start timer on button press 1 Answer
reset timer using a GUI button 2 Answers