Converting from Unity iPhone 1.7 to Unity 3 has been pretty sweet. Except for my GUI.Button scripts.
Now, in the editor, my GUI.Buttons are all scaled and nice. But when I build and run on iPhone they are all half the size they should be. I tried doubling their sizes in the script to compensate for the problem but the text inside the GUI.Button would not scale.
How could I solve this GUI.Button’s text size problem?
Oh! Also, is there a way to make my editor window within Unity 3 to be EXACTLY the same as the iphone’s? I know it has all the aspect sizes in the tab, but none of them depict what the build looks like running on iphone.
Then the text within the GUI.Button script is almost useless. Its too small and no matter how much you scale the button the text size remains the same. Should I report this?
Here’s a cool little trick to automatically resize all your GUI elements for retina (or iPad) display. Add these 3 lines to the start of your OnGUI call (note: you’ll probably want to pull the ‘scaledMatrix’ out as a variable that you calculate once in your Awake function):
function OnGUI() {
var screenScale: float = Screen.width / 480.0;
var scaledMatrix: Matrix4x4 = Matrix4x4.identity.Scale(Vector3(screenScale,screenScale,screenScale));
GUI.matrix = scaledMatrix;
// then do the rest of your GUI as per normal, using the 480x320 screen size you had for your standard res iPhone app
}
(I wish I’d known this trick 6 months ago when we were building universal versions of our apps!)
You don’t; you import fonts in the editor, and then apply them to GUIStyles/skins.
The only problem is that just scales stuff up, so it doesn’t look any better than it would on a non-retina display. It’s better than having a wrongly-sized GUI though.
When I go to my player settings for iOS the only possible changes to ‘Resolution and Presentation’ are Orientation and some Status Bar settings. I don’t see anything that allows me to change resolution to something lower.
This might be a little late for you, but I just started using Unity not too long ago so couldn’t reply back when you needed help =)
After you import your font into Unity, you should see it in the Projects list along with all your other imported goodies. Click on the font and in the inspector, increase your font size. Remember to click apply! Keep playing around with the size until it fits your buttons well.
If you’re having trouble applying a font to a GUI.Button, you have to declare a GUIStyle variable inside your script and attach the font to that GUIStyle. Then in your GUI.Button if statement, add the GUIStyle as the last parameter:
var textStyle: GUIStyle;
if(GUI.Button(new Rect(1, 2, 3, 4), “Text”, textStyle)){}
Totally general recommendation here but please, please, please don’t use Unity GUI in a production game with the default skin. Actually, you would be doing yourself a big favor if you didn’t use Unity GUI at all even with a skin. Having a nice GUI is something that is often overlooked but it is extremely important. The first impression a user will have of your app is the menu system. Unity GUI buttons don’t seem to have been designed with touch in mind. They don’t deselect on touch up and they just don’t feel right not to mention they are pretty horrendous looking. Spend some time on your GUI and make it look good and react well to touches. It will go a long way to making your game look and feel polished.
In my opinion it’s fine to use the default GUI as long as you customize it a bit. And that’s exactly what I will do.
I just have to get the high res display scaling right (without loosing image quality etc), as soon as that’s done I will start creating custom graphics.