Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to enlarge rect transform by script?

Discussion in 'UGUI & TextMesh Pro' started by leegod, May 30, 2016.

  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,308
    So I have text unity new ui object.

    I want to enlarge this text's recttransform vertically so it can show more texts inside.

    How can I do it at in-game dynamically?

    I googled and used,

    sysText.rectTransform.offsetMin, offsetMax,
    RectTransformExtensions.SetRightTopPosition(sysRect, new Vector2(0, -OneLineHeight * many));

    but neither works.
     
  2. crispybeans

    crispybeans

    Joined:
    Apr 13, 2015
    Posts:
    210
    this is what i do - since it found it the most solid on mobile - but there is some other ways of doing it as well.

    Code (CSharp):
    1. RectTransform rt = this.GetComponent<RectTransform>();
    2. rt.anchorMin = new Vector2( relativeX1, relativeY1 );
    3. rt.anchorMax = new Vector2( relativeX2, relativeY2 );
    4. rt.offsetMin = rt.offsetMax = Vector2.zero;
     
    Last edited: May 31, 2016
  3. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    I never used unityUI, so was curious..
    ..is 2nd one: rt.anchorMax = new Vector2( relativeX2, relativeY2 );