Performance: Coroutine basics (IEnumerator)
MEDIUM IMPACT
This concept affects how smoothly animations and timed events run without blocking the main game loop.
IEnumerator WaitThreeSeconds() {
yield return new WaitForSeconds(3f);
Debug.Log("3 seconds passed");
}
void Start() {
StartCoroutine(WaitThreeSeconds());
}void Update() {
float timer = 0f;
while (timer < 3f) {
timer += Time.deltaTime;
}
Debug.Log("3 seconds passed");
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking loop in Update | N/A | Blocks main thread | Freezes frame rendering | [X] Bad |
| Coroutine with yield return | N/A | Non-blocking | Smooth frame rendering | [OK] Good |