GUI label height dependant on text height?


I have an issue. I am wishing for the labels height to be dependant on the height of the content. The content is just text, with line breaking set in the GUIStyle. However, one size doesn’t fit all, and the background just look weird when its not fill with text.

GUI.Label(Rect(Screen.width - 400,40,400,200), myStrings[curString], myStyle); 

Any suggestions?

Thanks, Bobble.

You can use GUIStyle.CalcHeight for that, something along this:

GUIContent mgc = new GUIContent(myStrings[curString]);
float myHeight = myStyle.CalcHeight(mgc, 400);

Then, adjust your rect accordingly.

Good luck!