Camera can see an Object

Hi, i’ve got a quetion. I have a boolean in my script, and i want my boolean to be true, if the Camera looks in the direction of an object. I already tried

if(gameObject.renderer.isVisible)
{
   boolean = true;
}
else
{
   boolean = false;
}

but, everytime i do that, the boolean will return as true (in every situation).
Is there an other way, or am I doing something wrong?

What brian means is that if you're seeing the gameoject in the scene view renderer.isvisible will return true. Try turning the scene view to look into nothingness or compile a build.

Ok now there are two options. 1. brian converts his comment to a question and you can accept it. 2. You close the question but please thumbs up brian's comment :)

1 Answer

1

from Renderer.isVisible

Also, when running in the editor, the scene view cameras will also cause this value to be true.

Do check that link as there can be other quirks to using isVisible. If you need a more precise solution because of those issues, feel free to ask again