简体   繁体   English

我如何在脚本中更改 Unity 中的 Rect Transform

[英]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.

相关问题 内容大小调整器更新内容的矩形变换后,如何让 Unity 滚动矩形滚动到底部? - How do I get a Unity Scroll Rect to scroll to the bottom after the content's Rect Transform is updated by a Content Size Fitter? Unity,如何仅更改 GameObject 矩形变换的“顶部” - Unity, how to change only “top” of GameObject rect transform 想要在 canvas unity 上更改游戏对象(按钮)的矩形变换? - Want to change the Rect Transform of GameObject (Button) on canvas unity? 如何修改矩形变换的高度,同时使其看起来与以前的 position 相同? - How can I modify the height of a rect transform, while making it appear as it is the same position as before in unity? 如何统一动态编写视口矩形脚本 - How to Dynamically script viewport rect in unity unity UI 中 rect 变换的位置 - Position of rect Transform in unity UI 通过脚本统一更改转换对象 - unity change transform object through script 如何在 Unity 中向脚本化变换动画添加缓动? - How do I add easing to a scripted transform animation in Unity? 如何在 Unity 中另一个游戏对象的转换 position 实例化 object? - How do I Instantiate an object at the transform position of another GameObject in Unity? Unity-检查鼠标单击是否在rect转换内 - Unity - Check if mouse click was inside of a rect transform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM