How can I get an Ui's position relative to another UI's position in an unknown hierarchy

124 Views Asked by At

I have difficulty moving UI elements to one another on Unity.

I want to create a function that takes 2 RectTransforms and returns me a position of second objects relative to the first (don't mind more parameters if needed)

I want to move Equipments inner image to currency

enter image description here

RectTransfom a = Equipments inner image;
RectTransfom b = currency;

the problem is that both ui elements are childs and anchored to different places so I cannot do a simple lerp from b.position to a.position

because their position is relative to all of their parents

is there an easy solution to get the actual position without always calculating the position to the anchored to their parent (and so on till there is only the canvas)?

I've tried to receive the position and calculate it based on the anchored position but it seems that I need to do it until there is no parent which looks like not efficient way to do so but maybe I'm wrong

0

There are 0 best solutions below