SCRIPTING API / Scripts and entities / YieldInstruction
YieldInstruction
The base of the waits a coroutine can yield: WaitForSeconds, WaitForFixedUpdate and WaitForLateUpdate. Each instance decides when the coroutine continues; a WaitForSeconds counts down once, so create a new one for every wait. Game code cannot derive new wait types; loop with yield return null instead.
Kindclass
NamespaceKroys.EngineScripting
Members0
Source
Coroutine.csEXAMPLE
In a script
A complete script that uses YieldInstruction; copy it into your scripts project.
Coroutines.cs
public sealed class Countdown : EntityScript { protected override void OnStart() => StartCoroutine(Run()); private IEnumerator Run() { // Any YieldInstruction decides when the coroutine continues. YieldInstruction oneSecond = new WaitForSeconds(1.0f); for (int i = 3; i > 0; --i) { Debug.Log(i.ToString()); yield return oneSecond; // a used WaitForSeconds is spent: see below oneSecond = new WaitForSeconds(1.0f); // create a fresh one for every wait } Debug.Log("Go!"); } }
KroysEngine 0.1.0 documentation, built from the engine repository by Tools/BuildDocsSite.py.