[英]Unity : How can I get the list of gameobjects that are inside of Camera Frustum?
I want to get all the game objects that are visible inside of a particular camera frustum.我想获得在特定相机视锥体内可见的所有游戏对象。 The game scene can be seen in the following image.
游戏场景如下图所示。
The scene contains various game objects such as trees, buildings, cars and pedestrian.该场景包含各种游戏对象,例如树木、建筑物、汽车和行人。 I want to access those game objects.
我想访问那些游戏对象。 How can approach?
怎么能接近? Which Unity method I can use?
我可以使用哪种 Unity 方法? Please help.
请帮忙。
using UnityEngine;
public static class RendererExtensions
{
public static bool IsVisibleFrom(Renderer renderer, Camera camera)
{
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera);
return GeometryUtility.TestPlanesAABB(planes, renderer.bounds);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.