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?