
(You start a timer, you hang your loop, unless the timer is threaded).
JAVA TIMER UTILITY UPDATE
However setting a variable to the current time then checking it on each update or fixed update for a difference to match a total time works good. Wait timers aren't so good in your main loop. I encourage people to learn them and play with them, but for mercy sake please don't use them in a product you release until you really know what you are doing with them.Ī better coding practice for what you are describing would be to think logically through the entire situation. However you need to be careful using them, they are NOT thread safe, they are NOT even threaded (unless you make them that way), it is really advanced coding. If you insist on a fire and forget outside the main thread, then threading would probably be a better solution, just make a new thread, do your thing, then join back in.Ĭoroutines are powerful, when used right, you can set them up to be a parallel process and help handle heavy loads while letting your game smoothly truck along. One time task execution example, using schedule (TimerTask task, long delay) Fixed rate task example, using schedule (TimerTask task, long delay, long period) Fixed Rate task example using method, scheduleAtFixedRate (TimerTask task, long delay, long period) Using schedule (TimerTask task, long delay. They are designed to be a copilot, not a fire and forget. Coroutines in unity are best used to run something routine and regular while letting your normal game loop continue on its merry way instead of waiting for example a long for loop to finish. While you can stop a coroutine, they don't interact with unity objects, in fact you will make a mess of things.


You fire up a coroutine its gonna sit there and wait till you let it do its function again. Well coroutines are not the easy way for one shots.People use coroutines so wrong.
