- Home /
Timer reset after elapsed time.
I'm struggling with this one. At the moment I'm using something that basically works like this:
private var startTime : int = 0; private var roundTimeLeft : int = 0; public var roundTimeSeconds : int = 600;
function Awake () { startTime = Time.time; }
function Update () { roundTimeLeft = Time.time - startTime; }
I'd like the timer to reset to 0 in my if (roundTimeLeft >= roundTimeSeconds)
condition also located in update, and then continue counting upwards from 0. Any help would be much appreciated.
Answer by Mike 3 · Jul 15, 2010 at 10:51 AM
I think this should do it:
function Update ()
{
roundTimeLeft = Time.time - startTime;
if (roundTimeLeft >= roundTimeSeconds)
{
startTime = Time.time;
roundTimeLeft = 0;
}
}
Though the variable name (roundTimeLeft) is a little iffy, seeing as it's the opposite of the time left (it's how much has elapsed)
Wow, that was more simple than I thought. About the variable, yeah I realise it's iffy, I had originally intended for the timer to count down...
I was having the same problem and this helped a lot. Thanks. (super old post, I know.)
Your answer
Follow this Question
Related Questions
Timer variable set to zero 2 Answers
timer that can be reset 1 Answer
How to reset timer? (C#) 3 Answers
how to reset time 2 Answers
How do i reset a timer once it hits 0? 2 Answers