- Home /
How to get UI RectTransform bottom Y position?
Hello, my goal is to position an object, at the bottom of another object, through a script.
but i'm having trouble getting the correct position. Since the RectTransform position is Relative to the pivot, trying to get RectTransform.Ymax, doesn't get me the correct point. I think it gives a local point relative to the pivot.
I found out that with Tranform.GetWorldCorners(), I can get the corners sand through that, the bottom Y. But i was wondering if there is an easier and better way?
There's no good way of doing this that I've personally found. Everything dealing with UI seems to be relative to scale and pivot point (in some methods parent positioning effects it as well if I recall correctly). It seems you have to account for this in your code somehow. I'll show an example if necessary, too lazy to open up the project that does this right at this time.
I'm wrestling with this right now. It's a nightmare. I'll post here if I find a solution.
Answer by hexagonius · Feb 26, 2018 at 11:34 AM
I just used the same way
Vector3[] corners = new Vector3[4];
yourRectTransform.GetWorldCorners(corners);
Vector3 worldBottomCenter = Vector3.Lerp(corners[0], corners[3], 0.5f);
Your answer
Follow this Question
Related Questions
RectTransform returning incorrect rect bounds 0 Answers
How to find the bottom position of a Image based on it's height? 2 Answers
Rect Transform to World Position Conversion 2 Answers
Proper way to center a game object into an UI image? 1 Answer
Displaced UI RectTransform collider in some resolutions issue. 1 Answer