Hey guys, I’m doing some unity stuff. So far it’s great, however I still have some difficulties about scaling towards respective resolutions for mobile devices.
In general: I appreciate every suggestion!
So far I came across:
1 | GUI.DrawTexture(new Rect (0, 0, Screen.width, Screen.height), texture, ScaleMode.ScaleAndCrop); |
for scaling simple 2D textures. And a little script for rescaling fonts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class RescaleFonts : MonoBehaviour { private float _oldWidth; private float _oldHeight; private float _fontSize = 16; public float EffectiveFontSizePercent = 0.1f; // value between 0 and 1 void Update () { if (_oldWidth != Screen.width || _oldHeight != Screen.height) { _oldWidth = Screen.width; _oldHeight = Screen.height; _fontSize = Mathf.Min (Screen.width, Screen.height) * EffectiveFontSizePercent; guiText.fontSize = (int) _fontSize; } } } |
Where you add this script to a label or something and change its effective font size. So it will at least look a like amongst multiple devices. It scales all right but it doesn’t feel too reliable yet. Any suggestions?
How do you guys handle your ui sizes with unity?
February 4, 2014 at 10:40 pm
My quick & dirty approach:
this.guiText.fontSize = Screen.width/10;
But I’v got a very basic GUI wit only 3 text labels … everything else is done with sprites.
May 8, 2014 at 9:31 am
nice post
July 1, 2014 at 5:26 pm
Glad you like it. :) I’ll be making another post to this topic eventually again in the near future.