Search Unity

Text final render size

Discussion in 'UGUI & TextMesh Pro' started by SweetBro, Aug 28, 2014.

  1. SweetBro

    SweetBro

    Joined:
    Jan 14, 2013
    Posts:
    69
    Right so which variable represents the currently rendered bounds of a text? I've currently set a text object with both vertical/horizontal overflow, and I would like to be able to resize the boundaries of the it's parent panel based on the bounds generated by the text string, font, and font-size.
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Use:
    preferredHeight and preferredWidth to find the texts preferred sizes.
     
    pea and SweetBro like this.
  3. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Note that you shouldn't need to do scripting yourself if you just want the parent panel to adjust to the size of the child text (plus optional padding).

    Just add a HorizontalLayoutGroup as well as a ContentSizeFitter to the parent. In the new beta 18 there's also a page in the documentation called "Making UI elements fit the size of their content" with more information.