Hey, I searched on google on how to do this so I tried various different codes,
Here are some that I remember:
Renderer.IsVisible
Renderer.OnBecameVisible
and I’m currently with:
if(renderer.IsVisibleFrom(Camera.main))
{
print("You can see him");
}
(I also use a RendererExtension script so I can use “IsVisibleFrom”)
But once applied to an object, the “You can see him” is always spammed.
Anyone might happen to know how to check whether or not the maincamera can see a specific object?
You can easily test it in play mode when you move the object in the scene view behind the camera. Than the output immediately stops.
The method just just tests if the object is in the culling frustum of the camera (if the camera can see the object). It doesn’t check if the object is covered by other objetcs. Maybe this is what you want.
Oh, right! silly me!
The object is behind a wall and yet it sees me, I read something about layers in order to prevent this but I’m not sure, any ideas?
A long time ago I wrote a simple asset which determines wether a object is visible to the camera or not, using occluders to block the visibility, you can have a look into it, as far as I know there is a property in one of the components inside the asset which simply gives you the visibility state. Its worth a try:
I think there is something missing, as far as I know the walls need to be Occluders and not Occludables, there should be two different components for this, it has been a long time since I created these.