WaitForSeconds 等待秒数
Inherits from YieldInstruction
Suspends the coroutine execution for the given amount of seconds.
在给定的秒数内,暂停协同程序的执行。
WaitForSeconds can only be used with a yield statement in coroutines.
在coroutine中WaitForFixedUpdate只能用于yield声明。
C#
JavaScript
using UnityEngine;using System.Collections;public class example : MonoBehaviour {public IEnumerator Awake() {print(Time.time);yield return new WaitForSeconds(5);print(Time.time);}}
// Prints 0print (Time.time);// Waits 5 seconds 等待5秒yield WaitForSeconds (5);// Prints 5.0print (Time.time);
Constructors构造器
- WaitForSecondsCreates a yield instruction to wait for a given number of seconds