using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
IEnumerator Wait()
{
// suspend execution for 5 seconds
yield return new WaitForSeconds(5);
Debug.Log("Wait:"+Time.time);
}
void Start()
{
print("Start: " + Time.time);
// Start function WaitAndPrint as a coroutine
StartCoroutine("Wait");
print("Done:" + Time.time);
}
}
结果:
细节对比版
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
IEnumerator Wait()
{
// suspend execution for 5 seconds
yield return new WaitForSeconds(5);
Debug.Log("Wait:" + Time.time);
}
IEnumerator Start()
{
print("Start: " + Time.time);
// Start function WaitAndPrint as a coroutine
yield return StartCoroutine("Wait");
print("Done:" + Time.time);
}
}