ME FIRST GAMES
Menu
games for me and you
![]() Coroutines allow you to execute a sequence of code over multiple frames and empower you to write procedural animations and events over time. 📌 A normal method call, will run and return immediately when finished. 📌 A coroutine method call, can run, pause, run more later, and run to completion in later frame updates. Coroutines always execute on the main unity thread. 📌 Coroutines are great for coding a sequence of events over time. e.g. Playing an end screen animation: fill progress bar, wait, fly coins to the top, wait, fade in buttons. 📌 Coroutines have performance overhead, so you don't want to be starting hundreds every frame. However, invoking them once or twice per UI screen gives you all the benefits without the performance hit. 📌 yield return null - Pauses the coroutine and starts execution again the next frame, right after the Update call. 📌 yield return WaitForEndOfFrame - Pauses the coroutine and starts execution once the camera and GUI's are rendered this frame. 📌 yield return new WaitForSeconds - Pauses the coroutine and starts execution after x amount of seconds has passed. 📌 A common mistake is to abuse Coroutines and use them everywhere in your game. I rarely use Coroutines for anything besides the occasional UI animation sequence. 📌 Alternatives to Coroutines are Unirx, Async Methods, DOTween, and State Machines. 📌 Coroutines have gotten a bad wrap due to misuse. But they're a powerful tool when you invoke them carefully in your codebase.
0 Comments
Leave a Reply. |
Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
Red MatterStar Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.
Archives
April 2021
Categories |
Copyright (c) 2020 Me First LLC
|