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)
Best wishes for everybody,
- 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;
// 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;
That seems to be a real solution, and much cleaner than mine, I’d say. Thank you so much.