- Home /
Question by
h5nc · Mar 24, 2017 at 10:53 PM ·
uirecttransformpivotworldpos
How can I set a RectTransform's pivot like I do in inspector (so that it's world position changes as well)
Hi all,
I notice that when I set pivot on inspector, the RectTransform (as rt) remain unmoved in my scene. However if I change set
rt.pivot = new Vector2(0, 0);
in code, I find that my rect moved.
On inspector it changes the world position to keep its appearance in scene to stay the same. But calling in code will still keep the world position unchanged so that results in appearance changed due to pivot position changed.
How can I do the same thing of that on inspector in script? Notice that scale/rotation/pivot/anchor may take affection.
Comment
Answer by AhsanNaeem · May 11, 2017 at 06:30 PM
Try this.
NameOfGameObject.GetComponent<RectTransform>().pivot=new Vector2(1,1);
Same works fro rotation, pos, scale etc.