I want to know if the main camera is looking at an object. So far I found –
if (render.isVisible)
But is there anything more efficient?
I want to know if the main camera is looking at an object. So far I found –
if (render.isVisible)
But is there anything more efficient?
It’s not going to get much more efficient than that, since the property on it is set for you regardless, so may as well use it instead of calculating if the view frustum contains the object’s bounds.
That makes sense thank you
Keep in mind this also returns true if the object is behind a wall. isVisible only works with culling (clipping plane/FOV).
There are a couple of script functions that get called aswell: Unity - Scripting API: MonoBehaviour.OnBecameInvisible()
Be careful when testing this as the camera in the unity editor can count as being viewed by a camera.
I see, in that case what would be the best solution to avoid problems?
Not sure.
Maybe it would work with Occlusion Culling since that would hide objects behind walls.
Another option is using Raycast/Linecast to check line of sight.