我希望获得在特定相机视锥内可见的所有游戏对象。游戏场景可以在下图中看到。
场景包含各种游戏对象,如树木,建筑物,汽车和行人。我想访问那些游戏对象。怎么办?我可以使用哪种Unity方法?请帮忙。
答案 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);
}
}