using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { IEnumerator Example() { print(Time.time); yield return new WaitForSeconds(5); print(Time.time); } } Constructors 构造器 WaitForSeconds Creates a yield instruction to wait for a given number of seconds.创建一...
//After we have waited 5 seconds print the time again.Debug.Log("FinishedCoroutineat timestamp : " +Time.time); } } 另请参阅:MonoBehaviour.StartCoroutine、AsyncOperation、WaitForEndOfFrame、WaitForFixedUpdate、WaitForSecondsRealtime、WaitUntil、WaitWhile。
JavaScript => WaitForSeconds(seconds: float) C# => WaitForSeconds(float seconds) Description 描述 Creates a yield instruction to wait fo…
; // Promotional purchase has been detected. // Handle this event by, e.g. presenting a parental gate. // Here, for demonstration purposes only, we will wait five seconds before continuing // the purchase. StartCoroutine(ContinuePromotionalPurchases()); } private IEnumerator ContinuePromotional...
//Wait for two seconds yield return new WaitForSeconds(2); } 5、不能使用命名空间(Namespace) 当前的Unity不支持把脚本放到一个命名空间中。这可能在将来的版本中所有改变。 6、只有成员变量才能被序列化并显示在检查器中 私有和保护成员变量仅仅在专家模式(Expert Mode)下才显示在检查器中。属性不能被 ...
// suspend execution for 5 seconds yield return new WaitForSeconds(5); print("WaitAndPrint " + Time.time); } void Start() { print("Starting " + Time.time); // Start function WaitAndPrint as a coroutine StartCoroutine("WaitAndPrint"); ...
IEnumerator WaitAndPrint() { // suspend execution for 5 seconds yieldreturnnew WaitForSeconds(5); print("WaitAndPrint " + Time.time); } void Start() { print("Starting " + Time.time); // Start function WaitAndPrint as a coroutine ...
void Start() { // Kick off a separate routine that acts like a separate thread. StartCoroutine(Attack()); } IEnumerator Attack() { // Trigger an attack animation. _animator.SetTrigger("Attack"); // Wait for .5 to 4 seconds before playing attacking animation, ...
public void Awake() { // This will run FirstBeauRoutine, wait 5 seconds, then call Destroy(gameObject). Routine.Start(this, Sequence.Create(FirstBeauRoutine()) .Wait(5.0f) .Then(() => { Destroy(gameObject); }) ); } public IEnumerator FirstBeauRoutine() { ... }...
WaitUntil(() => isActive == false); // special helper of WaitUntil await UniTask.WaitUntilValueChanged(this, x => x.isActive); // You can await IEnumerator coroutines await FooCoroutineEnumerator(); // You can await a standard task await Task.Run(() => 100); // Multithreading, ...