O'Reilly logo

Unity 3 Game Development HOTSHOT by Jate Wittayabundit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Coroutine

StartCoroutine returns a coroutine. Instances of this class are only used to reference these coroutines and do not hold any exposed properties or functions.

A coroutine is a function that can suspend its execution of yield until 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);
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required