How to check if an object is being viewed by the camera and that there's nothing blocking the view?

Hello everyone. I’m trying to make a project with an enemy that only moves while you are not seeing him, like the Weeping Angels in Doctor Who. I already tried to create a collider for the field of view and to use OnWillRenderObject but I couldn’t find a way to make one of these check if the view is blocked. If anyone could help it would be great, thanks

For what you are doing, you can Linecast() from the eight corners of the collider.bounds. Since the bounds is a bit larger than the mesh, you will get some false positives when an object is close to being seen. If your scene has holes where the enemy can be seen through, you may want to add a few more Linecasts()…like to the pivot point.

In the answer referenced below, the Blocked() function would do the job, though you could make it a bit more efficient by having it return a boolean and bailing out on the checking when any Linecast() succeeds.