1
\$\begingroup\$

The usual way to set the width or height for a RectTransform is this one as far as I know : RectTransform.sizeDelta = new Vector2(...); . I want to set the width of my object in an EditorScript, so if I would use the mentioned method, I would automatically lock my height value in the editor. But I want to freely adjust my height and at the same time let the width be calculated from my script. So my problem is, that RectTransform.sizeDelta = new Vector2(...); is locking both values in the Editor.

\$\endgroup\$
  • 1
    \$\begingroup\$ Why not RectTransform.sizeDelta = new Vector2(calculatedWidth, RectRansform.sizeDelta.y)? \$\endgroup\$ – Maxim Kamalov Sep 6 '16 at 1:32
  • \$\begingroup\$ That's all the question is about, your line of code would lock the height in my editor, but I still want to adjust it. \$\endgroup\$ – TobiasW Sep 6 '16 at 6:08
  • 1
    \$\begingroup\$ Tried it like this: pastebin.com/Rpeu3YmJ Don't see any height locking. \$\endgroup\$ – Maxim Kamalov Sep 6 '16 at 12:08
  • \$\begingroup\$ Well shame on me for not trying your line of code... I did it like this : RectTransform.sizeDelta = new Vector2(calculatedWidth, RectRansform.rect.height); And that locked the height so I thought everything would do that... Thanks a lot! I would like to accept this as answer :) \$\endgroup\$ – TobiasW Sep 7 '16 at 5:52
2
\$\begingroup\$

You can read current height and set it again without changing. When you change height in the editor, it'll be changed between your code executions.

RectTransform.sizeDelta = new Vector2(calculatedWidth, RectRansform.sizeDelta.y)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.