判断物体是否在摄像机平面内

using UnityEngine;
using System.Collections;
 
public class IsDrawByCamera : MonoBehaviour {
 
    public GameObject  anObject;
    private Camera cam;
    private Plane[] planes;
    void Start()
    {
        cam = Camera.main;
         
    }
    void Update()
    {
             planes = GeometryUtility.CalculateFrustumPlanes(cam);//获得摄像机视景平面
            if (GeometryUtility.TestPlanesAABB(planes, anObject.collider.bounds))//测试平面(测试一个物体是否在摄像机视角内,无论它是否被渲染)
            {
                anObject.SetActive(true);
                Debug.Log(anObject.name + " has been detected!");
            }
            else
            {
                anObject.SetActive(false);
                Debug.Log("Nothing has been detected");
            }  
    }
 
}
原文地址:https://www.cnblogs.com/grassgarden/p/13725085.html