- Home /
Question by
rodeowild · Aug 16, 2020 at 04:23 PM ·
uirecttransform
Set UI Screen Position
I have two UI elements. I want to set the position of one equal to the position of the other (meaning they should have the same screen position). They do not have the same parent and there is no guaranteed anchoring configuration. How can I do that?
Comment
Best Answer
Answer by lvskiprof · Aug 17, 2020 at 09:31 PM
I would think something like this would work for you. Assuming you have a script for one of the UI elements and the other one you wish to lock to is called ui1 in this example:
void LockToUI1()
{
transform.position = new Vector2(ui1.transform.position.x, ui1.transform.position.y);
}
void Update()
{
.
.
.
LockToUI1();
.
.
.
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613005806im_/https://answers.unity.com/themes/thub/images/avi.jpg)