- Home /
Question by
varunstorm · Dec 27, 2013 at 11:11 AM ·
sizefontdisplay
How to increase font size of text displayed
I have a code snippet that displays some text on the screen. Is there any way to increase the font size and the font itself
This is the display code-
public var mess: String = "Hello";
function OnGUI()
}
GUI.Label (Rect (10, 30, 1000, 20),"Word: " +mess);
}
Comment
Answer by Eric5h5 · Dec 27, 2013 at 11:13 AM
Make a GUIStyle where the fontSize is the desired size and use that style in the label.
var myStyle : GUIStyle;
GUIStyle style = new GUIStyle();
style.fontSize = 130;
GUI.Label (new Rect (10, 10, 100, 20), "text", style);
Adjust the other style variables to your liking as it seems to use black color by default (it's usually white)
Dear ShadoX
When I do this the result is
Why is the text displayed twice
Is there something I missed
PS: I have changed the value of the variable "mess"
Sorry, the picture isn't working for me, could you upload it again? Perhaps you have "GUI.Label(.." twice somewhere?
Answer by sath · Jan 04, 2014 at 12:46 PM
Also you can do this:
var textStyle : GUIStyle ; //change settings from inspector
var mess : String = "Hello";
var resizeFont : float = 0.2;//change this to resize font (min=0,01 - max=0,5)
function OnGUI(){
//FONT RESIZE
textStyle.fontSize=Mathf.RoundToInt(Screen.height * resizeFont);
GUI.Label (Rect (10, 30, 1000, 20),"Word: " + mess , textStyle);
}