Hello there,
So, i’ve trying to implement my own timer system for my games, and I’ve faced a bit strange unexpected behaviour for Task.Delay (UniTask also) - when you run it in infinity loop it’s has accumulatin delay to compare with update or fixedupdate and other timer counters (and any timers example in web) and I’m wondering - why that’s happens?!
Thanks.
Because of how computers schedule work.
Just use a float
variable for a timer, update it yourself by adding Time.deltaTime, check if it’s time to do stuff.
When that variable exceeds your time, subtract the time interval, do your thing, and continue.
Keep it nice and simple: do it as above and no error will accumulate.
Cooldown timers, gun bullet intervals, shot spacing, rate of fire:
https://discussions.unity.com/t/821482/2
GunHeat (gunheat) spawning shooting rate of fire:
https://discussions.unity.com/t/824570/2
Very short timers… there’s just no need:
https://discussions.unity.com/t/886711/6