When I assing the position ot the element, it is not set exactly on the position it’s supposed to be in, but its getting offset everytime. How to calculate the exact position of the element in UI? I’ve tried world space and local space and nothing worked.
In the ui examples you can see the different offsets, even though the code is the same and their coordinates are also the same. When I click the left most slot button, the overlaying UI is on top of it, while when clicking on the right most button its next to it. Why is it like that and how to fix it, so that the ui is always next to the button regardless of the buttons’ position?
UI examples
code
public void BuildingSlotClicked()
{
buildingChooserUI.SetActive(!buildingChooserUI.activeInHierarchy);
if (buildingChooserUI.activeInHierarchy)
{
RectTransform rt = GetComponent<RectTransform>();
print(rt.localPosition);
RectTransform rtBuildingChooser = buildingChooserUI.GetComponent<RectTransform>();
rtBuildingChooser.localPosition = rt.localPosition; // + new Vector3(rt.sizeDelta.x * rt.localScale.x, 0);
print(rtBuildingChooser.localPosition);
}
}