I’ve spent a good amount of time trying to work this out. I haven’t read any posts that clarify this issue, and the documentation is completely baffling to me.
So, how do you move a RectTransform on the Pos X through code? I know how to edit the width and height of a panel or image, but I have no idea how to move it on the x or y. I’ve tried a lot of different things and got weird results. I suspect it has something to do with the pivot of the panel?
I had a similar problem. I was trying to instantiate a prefab and then have it populate the parent object.
I could not move it using localPosition or change the size using sizeDelta. To fix the issue, I used RectTransform.SetInsetAndSizeFromParentEdge().
rT.anchoredPosition = new Vector2(100f, 300f); // Sets the position to 100, 300
rT.anchoredPosition += new Vector2(1f, 3f); // Changes the position about 1 at the X-Axis and 3 at the Y-Axis
For me this code works quite well: public void MoveLeft(RectTransform panel) { StartCoroutine(Move(panel, new Vector2(-1255, 0))); } IEnumerator Move(RectTransform rt, Vector2 targetPos) { float step = 0; while (step < 1).