Khakis7
Khakis7

Reputation: 433

Unity Set position of GUI element relative to another element that is on a different canvas

I'm attempting to position a tooltip to be directly below an icon. The structure is:

Main Canvas
- Panel
 - UI Element
Tooltip Canvas
- Tooltip Icon

When mousing over an icon, I'm attempting to set the position of the tooltip to be just under the ui element. How does one get the absolute position of the ui element?

So far I've tried both

float absolute_x = icon.position.x;
or
float absolute_x = icon.anchoredPosition.x;

which only wield the relative position to the main canvas, not the absolute position on the UI.

Upvotes: 1

Views: 2038

Answers (1)

Art Zolina III
Art Zolina III

Reputation: 507

First get the Rectransform

public RectTransform UIElement;

then get position relative to the parent canvas

UIElement.localPosition.y

Upvotes: 2

Related Questions