[英]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.我想出了如何选择 position,而不是宽度和高度。
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;"我不确定我是否从未处理过更改 Rect Transform 的宽度,但您可以尝试将变量更改为类似“public RectTransform rt;”的内容then assigning the object to the variable.
然后将 object 分配给变量。 Or try "[SerializeField] RectTransform rt;".
或者试试“[SerializeField] RectTransform rt;”。 Although I'm not sure the variable would fix anything.
尽管我不确定该变量是否可以解决任何问题。 Hope this helps!
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.