Scan object within a range from up and down

How I can get a list of objects within a range of angle, for instance, from my facing direction, up and down 45 degree? I am noob in math and Unity.

Should I use a loop to cast a series of ray in the scan range?


Finding objects in a volume like that is a bit of a tricky problem. You could try iterating through all the relevant objects in the scene, and then performing a check on each one individually, but that can get a bit out of hand in large scenes, especially if there are a lot of candidate objects. If you were to use a loop, raycasting is probably not the way to go, unless you are checking for line-of-sight as well as position.

I just had an idea- you can press-gang frustrum culling for this! When you want to make the check, make a camera component on your object, set its FOV to 45, then use the GeometryUtility to calculate whether a given mesh is within its view frustrum. Of course, you still have to iterate through every mesh in the scene, which might get a bit slow. When you’re done, delete the camera (since you no longer need it).