Version: 2020.1

WaitWhile

class in UnityEngine

/

继承自:CustomYieldInstruction

切换到手册

描述

暂停协程执行,直到提供的委托评估为 /false/。

在协程中,WaitWhile 只能与 yield 语句结合使用。

每帧都会执行提供的委托,在脚本 MonoBehaviour.Update 之后 MonoBehaviour.LateUpdate 之前执行。当委托最终评估为 false 时,协程将继续其执行。

using UnityEngine;
using System.Collections;

public class WaitWhileExample : MonoBehaviour { public int frame;

void Start() { StartCoroutine(Example()); }

IEnumerator Example() { Debug.Log("Waiting for prince/princess to rescue me..."); yield return new WaitWhile(() => frame < 10); Debug.Log("Finally I have been rescued!"); }

void Update() { if (frame <= 10) { Debug.Log("Frame: " + frame); frame++; } } }

构造函数

WaitWhile使用要评估的给定委托实例化一个 yield 指令。

继承的成员

变量

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