How to tell if a RectTransform is within the visible area of a ScrollRect
Greetings,
Given a RectTransform R descended from another RectTransform containing a ScrollRect S (and a corresponding Mask), I'd like to know whether R is visible on the canvas given S's current scroll position.
Help! And thanks in advance!
Answer by KGC · Mar 02, 2017 at 11:24 AM
I've had a similar issue today, where I had a ScrollRect with UI elements inside of it, and I wanted to trigger a UI animation when a particular UI element became fully visible on screen, which only happens after the user scrolls down a bit. I believe this covers your use case as well.
I posted the code on the forums, so here's a link (to avoid having multiple copies of it, in case there will be edits): https://forum.unity3d.com/threads/test-if-ui-element-is-visible-on-screen.276549/#post-2978773
Hope this helps :)
Your answer
Follow this Question
Related Questions
UI Canvas Anchor points are stuck in the bottom left corner and disabled when in overlay mode. 1 Answer
Resize UI Panel to the same size as its parent Canvas through code 0 Answers
Updated with UI text element not correct (same frame) 0 Answers
RectTransform.anchoredPosition changes, but element is not visually updated 1 Answer
How to offset a RectTransform? 0 Answers