class in UnityEngine


Hereda de:YieldInstruction

Cambiar al Manual


Suspende la ejecución de la coroutine por la cantidad dada de segundos usando un tiempo escalado.

The real time suspended is equal to the given time divided by Time.timeScale. See WaitForSecondsRealtime if you wish to wait using unscaled time. WaitForSeconds can only be used with a yield statement in coroutines.

There are some factors which can mean the actual amount of time waited does not precisely match the amount of time specified:
1. Start waiting at the end of the current frame. If you start WaitForSeconds with duration 't' in a long frame (for example, one which has a long operation which blocks the main thread such as some synchronous loading), the coroutine will return 't' seconds after the end of the frame, not 't' seconds after it was called.
2. Allow the coroutine to resume on the first frame after 't' seconds has passed, not exactly after 't' seconds has passed.

using UnityEngine;
using System.Collections;

public class WaitForSecondsExample : MonoBehaviour { void Start() { //Start the coroutine we define below named ExampleCoroutine. StartCoroutine(ExampleCoroutine()); }

IEnumerator ExampleCoroutine() { //Print the time of when the function is first called. Debug.Log("Started Coroutine at timestamp : " + Time.time);

//yield on a new YieldInstruction that waits for 5 seconds. yield return new WaitForSeconds(5);

//After we have waited 5 seconds print the time again. Debug.Log("Finished Coroutine at timestamp : " + Time.time); } }


WaitForSecondsSuspende la ejecución de la coroutine por la cantidad dada de segundos usando un tiempo escalado.

Miembros heredados

Copyright © 2020 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。