此渲染器在任何摄像机中是否可见?(只读)
请注意,当对象需要在场景中渲染时,则认为它是可见的。例如,它可能实际上并不被任何摄像机看到,但仍然需要为了阴影而进行渲染。在编辑器中运行时,场景视图摄像机也会导致此值为真。
其他资源:OnBecameVisible,OnBecameInvisible。
//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"); } }