- Home /
Dynamic font size
How can I change the font size of a GUILabel according to the Screen.Height and Screen.Width data?
You'll want to set this in the actual GUIStyle that you use. Create your GUIStyle:
public GUIStyle myGUIStyle;
Then set the font size in code, like in your Start() method. Something like:
myGUIStyle.fontSize = Screen.width / 20;
Then make sure in your GUI.Label to specify this GUIStyle:
GUI.Label (new Rect (10, 10, 10, 10), "Blah, blah", myGUIStyle);
Thank you, but how can the size be affected by the height of the screen too?
font is usually affected by one number but you can try doing something like:
style.fontSize = (Screen.width+Screen.height)/60;
but i dont think thats what your looking for
If it's a 3d text mesh you could scale it that way then.
Answer by bloodyatheist · May 02, 2014 at 07:50 PM
you should try looking at the GuiStyle(it has alot of useful methods) and then add it to the created label:
GUIStyle style = new GUIStyle ();
style.fontSize = Screen.width/30;
GUI.Label(Rect,Text,Style);
Answer by YoungDeveloper · May 02, 2014 at 07:41 PM
Hi, it's better to use screen width, than height:
function Start(){
var screenXp:float = Screen.width/100.0;
myGUIStyle.fontSize = screenXp*2.6;
}
Your answer
Follow this Question
Related Questions
How to make dynamic font which is Simhei? 0 Answers
GuiText for Unity 4 dynamic scaling issue mobile 0 Answers
Is dynamic font supported on webplayer? 1 Answer
when android dynamicfont bug fix? 0 Answers