简体   繁体   English

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

[英]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.

相关问题 在Unity中,如何保存游戏对象列表(包括它们的状态)并使它们持久到下一个场景? - In Unity, how can I save a list of gameobjects, including their state and make them persist into the next scene? 如何在Unity中使GameObjects在屏幕上平滑转换? - How can I make GameObjects translate across the screen smoothly in Unity? 如何通过 X 坐标在 Unity 中将 GameObjects 居中? - How can I center GameObjects in Unity by X coordinate? 如何在 Unity 的相机视锥体中显示整个边界框 - how to Display an entire bounding Box in the Frustum of the camera in Unity 如何在列表中获取游戏对象的组件 - How to get component of gameobjects in a list 如何通过场景名称(仅一次)获取场景中的游戏对象列表? - How can I get list of gameobjects in a scene by scene name but only once? 如何获得数组或列出游戏对象下的所有子游戏对象? - How can i get in array or List all the child gameobjects under a gameobject? 如何获取所有附加了材质组件的游戏对象的列表? - How can I get a list of all gameobjects that have material component attached? 如何在 Unity 中仅获取具有 BlendShapes 的游戏对象 - How to get only GameObjects that have BlendShapes in Unity 如何让所有游戏对象检查哪些游戏对象有碰撞器,哪些游戏对象根本没有碰撞器? - How can I get all gameobjects to check what gameobjects have colliders and what colliders and what gameobjects dont have colliders at all?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM