- Home /
Relate font size to screen size in GUISkin
Hello everybody.
I have an annoying problem, and the worst is that I can figure that it'll be something obvious enough to make me feel embarrass once I get the answer. Anyway, lets go to the issue.
I'm making a simple GUI for an android application. I have related my buttons, text fields and boxes size to the Screen.width and Screen.height to keep the proportions and relative size. The problem comes because I don't know how to do the same with the texts (from labels and also from inside any element), which is not reduced when I reduce the screen size.
It's really a problem that must be solved because if I reduce the screen size to a normal Android phone the text inside textfield becomes bigger than the field itself.
I hope somebody knows how to solve this and wants to help a poor programmer as me. (tears) :D
Best wishes for everybody,
Alex.
Answer by GuyTidhar · Dec 05, 2012 at 12:58 PM
You could use GUI.matrix to scale the whole gui, instead of your way of scaling the buttons, text fields and buttons, and that will include the font.
You could have a list of supported screen sizes coupled with support font size, and when the the screen size is identified, choose the correct font size (need a dynamic font for that).
using the matrix example (option 1):
float originalWidth = 1024;
float originalHeight = 768;
void OnGUI()
{
// Set matrix
Vector2 ratio = new Vector2(Screen.width/originalWidth , Screen.height/originalHeight );
Matrix4x4 guiMatrix = Matrix4x4.identity;
guiMatrix.SetTRS(new Vector3(1, 1, 1), Quaternion.identity, new Vector3(ratio.x, ratio.y, 1));
GUI.matrix = guiMatrix;
// Do you GUI here
// Reset matrix
GUI.matrix = Matrix4x4.identity;
}
$$anonymous$$an, this worked great. Thank you very much, again. Good luck!
$$anonymous$$ight you give an example with a Gui.button pls? I don't understand how it works thanks :D
Thank you very much!! Do resetting the matrix really necessary? I've not seen differences commenting that line out.
Answer by Rosonator · Dec 05, 2012 at 02:17 PM
That seems to be a real solution, and much cleaner than mine, I'd say. Thank you so much.
Your answer
Follow this Question
Related Questions
Changing a GUILabel text SIZE 3 Answers
Changing the size of a GUI label 1 Answer
Can't draw GUI.Label text on subpixel values 0 Answers
GUI label/text appear/disappear 1 Answer