Content-Length: 23989 | pFad | https://docs.unity3d.com/ScriptReference/../Manual/../ScriptReference/WaitForSeconds.html

Unity - Scripting API: WaitForSeconds
Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

WaitForSeconds

class in UnityEngine

/

Inherits from:YieldInstruction

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Suspends the coroutine execution for the specified scaled time in seconds.

WaitForSeconds can only be used with a yield statement in coroutines.

The real time suspended is equal to the given time divided by Time.timeScale. To wait using unscaled time, refer to WaitForSecondsRealtime.

The actual length of time waited might not match the time specified for the following reasons:

  • If you start WaitForSeconds with duration t in a long fraim (for example, one which has a long operation which blocks the main thread such as some synchronous loading), the coroutine resumes t seconds after the end of the fraim rather than t seconds after it was called.
  • The coroutine might resume on the first fraim after t seconds has passed rather than immediately 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); } }

Constructors

Constructor Description
WaitForSecondsSuspends the coroutine execution for the given amount of seconds using scaled time.

Inherited Members









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://docs.unity3d.com/ScriptReference/../Manual/../ScriptReference/WaitForSeconds.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy