Version: 2018.2

WaitForSeconds

class in UnityEngine

/

継承:YieldInstruction

マニュアルに切り替える

説明

スケール化した時間を使用して、指定した秒数の間コルーチンの実行を待ちます。

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.

いくつか要因があり、実際に延期する時間が指定された時間と正確には一致しないことがあります。

- WaitForSeconds は現在のフレームの 終了時 に待機を始めます。そのため、持続時間 't' を持つ WaitForSeconds をとても長いフレーム (例えば、同期的な読み込みなどのメインスレッドをブロックするような長い操作があるフレーム) で開始すると、コルーチンは、呼び出し後にではなく、そのフレームの終了 に 't' 秒を返します。

- WaitForSeconds によって、コルーチンは正確に 't' 秒後ではなく、't' 秒後に最初のフレームから再開することが可能です。

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); } }

コンストラクタ

WaitForSecondsスケール化した時間を使用して、特定の秒数だけ待機するという yield 指示を作成します

継承メンバー

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