Version: 2021.3

MonoBehaviour.OnBecameInvisible()

切换到手册

描述

OnBecameInvisible 在渲染器对任何摄像机都不可见时调用。

该消息将发送到附加到渲染器的所有脚本。 OnBecameVisibleOnBecameInvisible 有助于避免仅在对象可见时才需要进行的计算。

// Disables the behaviour when it is invisible

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { void OnBecameInvisible() { enabled = false; } }

OnBecameInvisible 可以作为协程使用 - 在函数中使用 yield 语句即可。 在 Editor 中运行时,Scene 视图摄像机也会导致调用该函数。