I have a situation where i must spawn, move or animate different objects in random time intervals.
At this moment, i’m running few timers in Update(), do stuff when they reach zero, and reset them to the random value. That works ok, but i’m concerned about performance. There will be no more than 5-8 timers total.
So, should i leave it like this, use yield, or maybe, as last resort, InvokeRepeating?
if it works and the script performance is not causing problems… why change it?
invokerepeating is for fixed intervals which you might not want. yield or coroutines are ok as well but i don’t see a performance benefit compared to a few timers. especially if we walk about small numbers you can use what ever you want i think.
You can always use Invoke as well. Takes a time parameter and is probably more suited to what you are looking for.
If performance is your aim, there are several more important things to consider…
Only do rotation/translation/animation/input in your Update functions
Only do force/torque in FixedUpdate
If you are using Translate/Rotate on a gameobject that has a rigidbody, you’re doing it very wrong (fixing this will improve performance a lot more than taking out a few timers)
Use InvokeRepeating for tasks that need to happen frequently, but not every frame (AI/pathfinding/targetting)