unity 检测物体是否在相机视野范围内

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BaiYangShouTong/article/details/54882787

脚本挂在摄像机要显示的对象上

前提:该对象有 render 组件

public class visibleTT : MonoBehaviour
{
    public bool isRendering = false;
    public float lastTime = 0;

    public float curTime = 0;


    void Update()
    {

        if (lastTime != curTime)
        { 
            isRendering = true;
            Debug.Log("In View");
        }

        else
        { isRendering = false;
          Debug.Log("Not In View");
        }


        lastTime = curTime;

    }


    void OnWillRenderObject()
    {

        curTime = Time.time;

    }
    
}


猜你喜欢

转载自blog.csdn.net/BaiYangShouTong/article/details/54882787