CanvasRenderer.isVisible?

Regarding new Unity 4.6 UI:

Is there a way to know if the ui is inside the viewing angle of the camera? Just like we use Renderer.isVisible? Is there any similar API for CanvasRenderer? If no, then how can we achieve the same with UI? Any ideas?

Thanks in advance.

2 Answers

2

There is no straight forward variable or method available that you can access to get the visibility as you intend as per the CanvasRenderer scripting reference.

But what you can do is get the rectangle for the canvas to which your game object of UI element belongs using Canvas.pixelRect and then check if your particular game object for the UI element lies within the boundaries of your canvas in overlay mode. You can check it using the collision technique used to check for two rectangles in simple 2D physics.

In world space mode for canvas, you can check the same within the boundaries of your camera since your game object might not be in the canvas rect but is present inside the camera frustum.

You can get the render mode for your canvas using Canvas.renderMode

Thanks very much for the workarounds. I wasn't thinking straight.

check this: https://forum.unity3d.com/threads/test-if-ui-element-is-visible-on-screen.276549/#post-2978773