- Home /
Display label for different screensize
I need to display label for different screen sizes on android. I used below code. When i running on device label displaying 2 times. Is if condition not working?
if(Screen.height >= 1280){
GUI.skin.label = style_1;
GUI.skin.label.padding.top=200;
GUILayout.Label("1. Print the alphabet image targets located at", style_1);
}
if(Screen.height >= 800){
GUI.skin.label = style;
GUI.skin.label.padding.top=100;
GUILayout.Label("1. Print the alphabet image targets located at", style);
}
Comment
If Screen.height >= 1280, then it is also > 800 which is why you get the label twice; IF condition is working as you have it, refine the logic or try out the Answer below.
Answer by zharik86 · Jan 16, 2014 at 08:13 AM
In your case it is necessary to use GUI.matrix:
void OnGUI() {
//write your GUI elements for one screen resolution, for example, 1280x720
float scalex = (float)(Screen.width) / 1280.0f;
float scaley = (float)(Screen.height) / 720.0f
GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(scalex, scaley, 1);
//and, for example, I create label with text
GUI.Label(new Rect(0, 200, 600, 100), "1. Print the alphabet image targets located at");
}
I hope it to you will help.
thanks bro, this helped me a lot to scale all my gui windows labels and buttons easier
Why would you even use the old GUI? The new UI can auto-scale, or stretch to fit.