Scaling GUI.Labels to screen

Hi all,

I only just managed to get most of my game to correctly scale on different Android devices. GameObjects and such scale fine, but GUI.Labels fail to shrink in size along with them, making them clutter much more of the screen than they need to.

The POSITION of the text is fine. It’s just the text size that won’t adjust.

Here is a sample of my code:

    	void OnGUI()
    	{
    		GUIStyle myStyle = new GUIStyle();
    		myStyle.font = myFont;
    		myStyle.fontSize = 40;
    		myStyle.normal.textColor = Color.white;
    	
    		myStyle.alignment = TextAnchor.UpperLeft;
    		GUI.Label (new Rect (10, textYPos, 500, 20), "TIME : " + 
                timer.ToString("F2"), myStyle);
        }

Anyone have a solution?

For your case best of all the following code will approach. For example, you have LandScape orientation and for the size screen 1920 the size of the text is equal 40. Then:

 void OnGUI() {
  GUIStyle myStyle = new GUIStyle();
  myStyle.font = myFont;
  myStyle.fontSize = (int)(40.0f * (float)(Screen.width)/1920.0f); //scale size font
  myStyle.normal.textColor = Color.white;

  myStyle.alignment = TextAnchor.UpperLeft;
  GUI.Label (new Rect (10, textYPos, 500, 20), "TIME : " + timer.ToString("F2"), myStyle);
 }

Probably, it is better for you to use GUI.matrix for scaling of all GUI elements. I hope that it will help you.