Game Development Reference
In-Depth Information
// C# user:
void Start() {
// Starting = 0.0
Debug.Log ("Starting = " + Time.time);
StartCoroutine(WaitAndPrint(5.0f));
// Before WaitAndPrint = 5.0
Debug.Log ("Before WaitAndPrint = " + Time.time);
}
IEnumerator WaitAndPrint(float waitTime) {
//Suspend execution for 5 seconds
yield return new WaitForSeconds(waitTime);
// WaitAndPrint = 5.0
Debug.Log ("WaitAndPrint = " + Time.time);
}
The following example will wait until the WaitAndPrint() function has finished its
execution and then continue executing the rest of the code in the Start() function:
// JavaScript user:
function Start() {
// Starting = 0.0
Debug.Log ("Starting = " + Time.time);
// StartCoroutine WaitAndPrint (In JavaScript, you can
also useyield WaitAndPrint(5.0) which will get the same
result.
yield StartCoroutine(WaitAndPrint(5.0));
// Done WaitAndPrint = 5.0
Debug.Log ("Done WaitAndPrint = " + Time.time);
}
function WaitAndPrint(waitTime : float) {
//Suspend execution for 5 seconds
yield WaitForSeconds(waitTime);
// WaitAndPrint = 5.0
Search WWH ::




Custom Search