- Home /
Subtracting variable every second
How can I subtract a variable every second without using the Invoke function? Can anyone give me an example?
Why wouldn't you use Invoke (or, more accurately, InvokeRepeating)?
Answer by xt-xylophone · Mar 20, 2013 at 10:49 PM
At your start function you could save the current Time as variable and then during your update function you could check whether the difference between current time and the saved time is greater than your desired time step(1 sec) then do your variable changes and set the saved time as the current time so the next time around the Update function will do this check again.
Not 100% sure whether it will bang on 1 second due to its only check when the Update function is called and may for instance check at 0.9 sec and 1.1 sec and would do the call at 0.1 sec later than you want. But you can always add more controls to it like changing the update time dynamically which you cant do with InvokeRepeating, or can you?? dunno...
Hope that helps!