- Home /
Answer by Seth-Bergman · Jul 25, 2012 at 11:59 PM
Well, to see if it is within view of any camera, you can check renderer.isVisible:
if(renderer.isVisible) // camera can see it
if you mean, is it in line of sight of the character, that's a bit more complicated though, you would probably use a raycast forward from the character object.. not sure which you mean
i will note that this also works in the editor screen, so you will have to debug.
This seems like exactly what i need, thank you. This would attach to the game object that needs to be detected, correct?
correct.. generally, when you see a lower-case keyword, such as transform.position, gameObject.GetComponent(), or in this case "renderer.isVisible", the "renderer" is a keyword which refers to the Renderer Component on this game object. If I wanted to access it from another script, I could do so via a variable:
var theObject : GameObject = GameObject.Find("SomeObjectName");
if(theObject.renderer.isVisible) etc....
Btw. isVisible and OnBecameVisible / OnBecameInvisible are influenced by ALL cameras. If the object is in view of any camera (the scene-view-camera is also a camera), the object will be declared as visible. So keep that in $$anonymous$$d when you test in the editor.
Your answer
Follow this Question
Related Questions
OnCollisionEnter can't find 'Player'? 3 Answers
how to detect wich item i have in my inevntory 0 Answers
Unity Camera Jerking On Following Player 1 Answer
Network View mess up colliders? 0 Answers
Player moving out of raycast 3 Answers