Tutorial by Examples

First it's essential to understand that, game engines (such as Unity) work on a "frame based" paradigm. Code is executed during every frame. That includes Unity's own code, and your code. When thinking about frames, it's important to understand that there is absolutely no guarantee of w...
Often you design coroutines to naturally end when certain goals are met. IEnumerator TickFiveSeconds() { var wait = new WaitForSeconds(1f); int counter = 1; while(counter < 5) { Debug.Log("Tick"); counter++; yield return wait; } ...
There are three MonoBehaviour methods that can be made coroutines. Start() OnBecameVisible() OnLevelWasLoaded() This can be used to create, for example, scripts that execute only when the object is visible to a camera. using UnityEngine; using System.Collections; public class RotateObje...
Coroutines can yield inside themselves, and wait for other coroutines. So, you can chain sequences - "one after the other". This is very easy, and is a basic, core, technique in Unity. It's absolutely natural in games that certain things have to happen "in order". Almost every...
You can wait until the next frame. yield return null; // wait until sometime in the next frame You can have multiple of these calls in a row, to simply wait for as many frames as desired. //wait for a few frames yield return null; yield return null; Wait for approximately n seconds. It is ...

Page 1 of 1