简体   繁体   中英

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? 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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM