Game Development Reference
In-Depth Information
Example
function Start() {
// Wait for FixedUpdate to finished
yield new WaitForFixedUpdate();
// Call After FixedUpdate
Debug.Log ("Call after FixedUpdate");
}
function FixedUpdate() {
Debug.Log ("FixedUpdate");
}
Coroutine
StartCoroutine returns a corouine. Instances of this class are only used to reference
these corouines and do not hold any exposed properies or funcions.
A coroutine is a funcion that can suspend its execuion of yield unil the given
YieldInstruction finishes.
Example
function Start() {
// Starting = 0.0
Debug.Log ("Starting = " + Time.time);
// Start function WaitAndPrint as a Coroutine
yield WaitAndPrint();
// Done WaitAndPrint = 5.0
Debug.Log ("Done WaitAndPrint = " + Time.time);
}
function WaitAndPrint() {
//Suspend execution for 5 seconds
yield WaitForSeconds(5);
// WaitAndPrint = 5.0
Debug.Log ("WaitAndPrint = " + Time.time);
}
 
Search WWH ::




Custom Search