Unity 3 causes GUI.Button to be much smaller

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.

Switch your build target to iOS.

?

I’m building and running on my iPhone. Can you do that without its target being IOS?

Um, is it the retina display support in Unity 3? Because my texture buttons are smaller too.

That is the most likely reason…

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?

No, that’s how it’s supposed to work. If you want bigger text, import the font at a larger size.

–Eric

How would you import font into a if (GUI.Button(Rect(10,70,50,30),“Click”)) ?

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.

–Eric

Ok so here’s the difference. And this is using the same code! The first is in Unity 1.7. The second is in Unity 3.

You see how the text within the buttons are way tiny? I button width and height are correct but how do I adjust the text size?

Edit:

someone else had the same question but there wasno reply

http://forum.unity3d.com/threads/45769-How-do-I-change-the-size-of-the-text-in-a-GUI-Button?highlight=gui+button+text+size

I had the same problem. In Player settings I changed the resolution to “medium to low” and it worked great.

the buttons have the same size but your font also, which is a problem if you run it at retina resolutions where the font would need double size

In Unity 3?

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.

No matter how I scale the buttons, the font size remains the same. :confused:

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)){}

Hope that helps!

I’m having the exact same issue. My buttons didn’t scale, now I got them to scale (with an ugly workaround) and the text is still tiny as hell.

Sorry for double post, but I just found this:
http://forum.unity3d.com/threads/58161-Unity-3-b6-iPhone-Fonts-problem

Sounds exactly like my problem, I also get font errors in the Xcode console. Could you check your console for those errors?

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.