How to determine an object is in view port of camera or not?

I want to determine an object is in view port of camera or not. For example, if an object is currently visible, I can interact with in, but not, I can’t do anything with it.

How can I do this?

Thank you very much.

You could use the OnBecameVisible and OnBecameInvisible callbacks.

Thank you for you suggestion. But OnBecameVisible/OnBecameInvisible are called when the object is visible/invisible by any camera. How can I determine that it’s visible by the current camera?

transform its coordinate into camera coordinates and check if it is in front of it and within a given ± x / ± y range offsetwise.

Thank you for your suggestion.

I’m still afraid of continuously transforming its coordinate and then checking (I’m assumed that code will be added to Update() function).

With OnBecameVisible/OnBecameInvisible, I just need to check once.

Actually thats not correct. Its checked all the time as well otherwise it couldn’t be fired.

But you can use a special layer that ensures that the object is only rendered on a single cam and can thus only fire it on that cam for example
or see in the onbecamevisible if it is in front of the right cam

but either way, you will have to do additional calculations if you want to have multi cam + “lazy solution”

I did it! Thank you so much :smile: