Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

WaitForSeconds

class in UnityEngine

/

Hereda de:YieldInstruction

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual

Descripción

Suspends the coroutine execution for the given amount of seconds using scaled time.

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

Note: There are some factors which can mean the actual amount of time waited does not precisely match the amount of time specified.

- WaitForSeconds starts waiting at the end of the current frame. So, if you start a WaitForSeconds with duration 't' in a very 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.

- WaitForSeconds will allow the coroutine to resume on the first frame after 't' seconds has passed, not exactly after 't' seconds has passed.

// Prints 0
print (Time.time);
// Waits 5 seconds
yield WaitForSeconds (5);
// Prints 5.0
print (Time.time);
using UnityEngine;
using System.Collections;

public class WaitForSecondsExample : MonoBehaviour { void Start() { StartCoroutine(Example()); } IEnumerator Example() { print(Time.time); yield return new WaitForSeconds(5); print(Time.time); } }

Constructores

WaitForSecondsCreates a yield instruction to wait for a given number of seconds using scaled time.

Miembros heredados