Version: 2021.2

MonoBehaviour.OnBecameVisible()

切换到手册

描述

OnBecameVisible 在渲染器变为对任意摄像机可见时调用。

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

// Enables the behaviour when it is visible

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { void OnBecameVisible() { enabled = true; } }

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