Measure Text

Is there any way to measure the rectangle for a text string prior to rendering it? I am trying to define a message box control that always keeps the content text centered (mathematically) and I want to make sure that the message box rectangle scales to its content dynamically.

Thanks :slight_smile:

You can use CalcSize

var fontStyle : GUIStyle = new GUIStyle();
var defaultFont : Font;
fontStyle.font = defaultFont;

var myWidth = fontStyle.CalcSize(GUIContent( "myStringToTest" )).x

But can’t you just set the label to center aligned?