简体   繁体   中英

How do i change the Rect Transform in Unity in a script

I am trying to change the Width and, height in a Rect Transform. But i cant change it in my script. Does anybody know how to change it?

I found this and tried it but it didn't work

RectTransform rt = canvas.GetComponent<RectTransform>();
rt.sizeDelta = new Vector2(700, 500);

I figured out how i could choose the position, but not the width and height.

I'm not sure i have never dealt with changing the width of a Rect Transform but you can try changing the variable to something like "public RectTransform rt;"then assigning the object to the variable. Or try "[SerializeField] RectTransform rt;". Although I'm not sure the variable would fix anything. Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM