首页 > Python基础教程 >
-
C#教程之C#应该掌握的一些东西(2)
}
}
using UnityEngine;using System.Collections;
public class example : MonoBehaviour {
void Start() {
print("Starting " + Time.time);
StartCoroutine(WaitAndPrint(2.0F));
print("Before WaitAndPrint Finishes " + Time.time);
}
IEnumerator WaitAndPrint(float waitTime) {
yield return new WaitForSeconds(waitTime);
print("WaitAndPrint " + Time.time);
}
}
using UnityEngine;using System.Collections;
public class example : MonoBehaviour {
IEnumerator Do() {
print("Do now");
yield return new WaitForSeconds(2);
print("Do 2 seconds later");
}
IEnumerator Awake() {
yield return StartCoroutine("Do"); //Yield StartCoroutine就代表中断式的协同工作
print("Also after 2 seconds");
print("This is after the Do coroutine has finished execution");
}
}
using UnityEngine;using System.Collections;
public class example : MonoBehaviour {public static IEnumerator Do() {
print("Do now");
yield return new WaitForSeconds(2);
print("Do 2 seconds later");
}void Awake() {
Do(); //执行DO,但是do后的语句继续执行
print("This is printed immediately");
}