public bool isVisible ;

描述

该渲染器是否在任何摄像机中可见?(只读)

注意,当需要在场景中渲染某个对象时,则认为该对象可见。例如, 有的对象实际上可能不会被任何摄像机看到,但由于阴影原因仍需要渲染。 在 Editor 中运行时,Scene 视图摄像机也会导致该值为 true。

另请参阅:OnBecameVisibleOnBecameInvisible

//Attach this script to a GameObject with a Renderer component attached
//If the GameObject is visible to the camera, the message is output to the console

using UnityEngine;

public class IsVisible : MonoBehaviour { Renderer m_Renderer; // Use this for initialization void Start() { m_Renderer = GetComponent<Renderer>(); }

// Update is called once per frame void Update() { if (m_Renderer.isVisible) { Debug.Log("Object is visible"); } else Debug.Log("Object is no longer visible"); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961