Game Development Reference
In-Depth Information
// JavaScript user:
function Start() {
// StartCoroutine(Do()) (In JavaScript, you can also use
DO() whichwill get the same result.
StartCoroutine(Do());
Debug.Log ("This is printed immediately");
}
function Do() {
Debug.Log ("Do now");
yield WaitForSeconds (5); //Wait for 5 seconds
Debug.Log ("Do 5 seconds later");
}
// C# user:
void Start() {
StartCoroutine(Do());
Debug.Log ("This is printed immediately");
}
IEnumerator Do() {
Debug.Log ("Do now");
yield return new WaitForSeconds (5f); //Wait for 5
seconds
Debug.Log ("Do 5 seconds later");
}
The following example will execute Do() and wait until Do() has finished waiting for 5
seconds before continuing its own execution:
// JavaScript user:
//Chain Coroutine
function Start() {
yield StartCoroutine(Do());
Debug.Log ("This is printed after 5 seconds");
Search WWH ::




Custom Search