- Home /
Know if gameObject is being seen
Hi people!
Is there a quick way to check if gameObject is inside a camera's view? I mean, if the user can see it on the screen, if there's no wall blocking it, or if its inside the camera's field of view, etc...?
Thanks!
$$anonymous$$eep in $$anonymous$$d that a GameObject can't be seen, only a Renderer component that might be attached to the GameObject.
Answer by reptilebeats · Aug 21, 2012 at 11:25 PM
put this on an object to start this function when it became visable by the camer
function OnBecameVisible(){
//do something
}
and use this in a function to do something if it is visable
if(renderer.isVisible){
//do something
}
these will both work when your editor view is on the object as well so use a debug in them to check it
no probs it had me stumped when i first used it to play some animation, thought it wasnt working until i realised it worked with the editor window as well.
Yes, you spared me some hours of life by warning about that hehe :)
Fixed your answer: your wrote OnBecameVisable
ins$$anonymous$$d of OnBecameVisible
.
did i woops, thank god for mono develop auto selection
Answer by ehliel · Oct 17, 2016 at 05:00 AM
OnBecameVisible is always run?
and renderer.isVisible is not even available in the compiler (it is not known)?
i still spend hours in this matters
please reply here and alert me @ e2444@yahoo.com