Hi, I am in situation when I need to change button anchors position from script. Currently my anchors are located exactly in the button corners (because I want this button to be scalable when changing screen size) and I would like to move it to the parents element top left corner (practically use anchor preset “top-left”). My answer is how can I achieve this through script? I`ve tried to change anchors min-max setting to the values which are displayed in inspector when you select Top-Left preset and I did it like this:
RectTransform rt = myButton.GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0, 1);
rt.anchorMax = new Vector2(0, 1);
Problem is the anchor position has really moved to parents top-left corner, but my button completely disappeared (yeah, just disappeared, it is not located anywhere in the scene). This leads me to conclusion that I need to change more rectTransform variables to reach my goal… Can somebody please help?