- Home /
GUI font size help
Is there a way to make the font size consistent throughout devices? Like with other GUI elements, you can do screen.width and screen.height stuff, so I was wondering if you could make the font size of a GUI Button to be like a fraction of the button size instead of checking and changing, because the last time I made an app, the Font was wayyyy to small when I tested for android.
Answer by zharik86 · Sep 20, 2014 at 07:06 AM
Of course, you are able to do it. The truth, for scaling of GUI elements is better to use GUI.matrix instead of Screen.width and Screen.height. But for your case create new GUIStyle in your Assets folder (the right click -> Create GUIStyle). Set in it necessary parameters, and in a script give the reference to it and use in OnGUI (). The example is lower(write on CSharp):
public GUIStyle myStyle = null; //reference on your style
void Start() {
//For example, font size for screen width = 1920 is equal 30, then calculate new font size
myStyle.fontSize = (int)(30.0f * (float)(Screen.width) / 1920.0f);
}
void OnGUI() {
//Use your style for text
GUI.Label(new Rect(25, 25, 200, 100), "This is label", myStyle);
//And etc
}
But don't forget change normal color text into style: yourStyle->normal->TextColor. Use white. I hope that it will help you.
Your answer
Follow this Question
Related Questions
GUI button in middle of screen 2 Answers
How do I code a GUI/HUD for various Android resolutions and Screen densities? 0 Answers
Fit GUI to various android screen resolutions and densities 6 Answers
Android/IOS GUI Rescale 0 Answers
Multitouch Android 1 Answer