Unity:如何获取Camera Frustum内部的游戏对象列表?

时间:2017-12-04 08:03:53

标签: c# unity3d

我希望获得在特定相机视锥内可见的所有游戏对象。游戏场景可以在下图中看到。

See the image here

场景包含各种游戏对象,如树木,建筑物,汽车和行人。我想访问那些游戏对象。怎么办?我可以使用哪种Unity方法?请帮忙。

1 个答案:

答案 0 :(得分:0)

using UnityEngine;

public static class RendererExtensions
{
    public static bool IsVisibleFrom(this Renderer renderer, Camera camera)
    {
        Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera);
        return GeometryUtility.TestPlanesAABB(planes, renderer.bounds);
    }
}