Detecting GameObject in a view of a Camera

Hi,

How can I detect whether a GameObject is seen by a Camera or being currently rendered on screen?

About OnBecameVisible and OnBecameInvisible, there seems to be two tricks :

  • When you launch the game, if the gameobject is in the camera frustum (between the near and far clip), OnBecameVisible is triggered. The inverse is false : when you launch the game, if the gameObject is not in the camera frustum, OnBecameInvisible is not triggered.
  • Even if the gameObject is not visible (behind another gameObject), OnBecameVisible will be triggered anyway.
1 Like

Thanks, that was so simple :wink:

seem it simple, but if I want appear a popup when detected gameobject by camera, how can i do? Thanks1778328--112871--Screen Shot 2014-09-17 at 2.54.38 PM.png 1778328--112872--Screen Shot 2014-09-17 at 2.53.48 PM.png

If you keep track of a true/false boolean variable, and change it to true when the object is visible, back to false when not, then in GUI do something like:

//isVisible is the boolean variable
if (isVisible) {
//display dialog gui
}

Hope this makes sense and helps! :slight_smile:

1 Like