- Home /
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.
Answer by HarshadK · Sep 09, 2014 at 10:12 AM
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.
Answer by unmaxim · Mar 09, 2017 at 08:04 PM
check this: https://forum.unity3d.com/threads/test-if-ui-element-is-visible-on-screen.276549/#post-2978773
Your answer
Follow this Question
Related Questions
Problem with sprite animation on android 1 Answer
Reduce Draw Call for Sprite 1 Answer
Help with changing spririterenderer's sprite 2 Answers
Accessing FilterMode possible on a 2D sprite? 1 Answer
Sprite renderer or mesh renderer 0 Answers