Search Unity

Unity 3 causes GUI.Button to be much smaller

Discussion in 'iOS and tvOS' started by QuantumCalzone, Nov 23, 2010.

  1. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    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.
     
    Last edited: Nov 23, 2010
  2. defjr

    defjr

    Joined:
    Apr 27, 2009
    Posts:
    436
    Switch your build target to iOS.
     
  3. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    ?

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

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    Um, is it the retina display support in Unity 3? Because my texture buttons are smaller too.
     
  5. psyclone

    psyclone

    Joined:
    Nov 17, 2009
    Posts:
    245
    That is the most likely reason...
     
  6. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    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?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, that's how it's supposed to work. If you want bigger text, import the font at a larger size.

    --Eric
     
  8. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    How would you import font into a if (GUI.Button(Rect(10,70,50,30),"Click")) ?
     
  9. ezone

    ezone

    Joined:
    Mar 28, 2008
    Posts:
    331
    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):

    Code (csharp):
    1.  
    2.  
    3. function OnGUI() {
    4.      var screenScale: float = Screen.width / 480.0;
    5.      var scaledMatrix: Matrix4x4 = Matrix4x4.identity.Scale(Vector3(screenScale,screenScale,screenScale));
    6.      GUI.matrix = scaledMatrix;
    7.  
    8.      // then do the rest of your GUI as per normal, using the 480x320 screen size you had for your standard res iPhone app
    9. }
    10.  
    11.  
    (I wish I'd known this trick 6 months ago when we were building universal versions of our apps!)
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    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
     
  11. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    Last edited: Nov 25, 2010
  12. bnolan

    bnolan

    Joined:
    Feb 3, 2010
    Posts:
    10
    I had the same problem. In Player settings I changed the resolution to "medium to low" and it worked great.
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    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
     
  14. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    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.
     
  15. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    No matter how I scale the buttons, the font size remains the same. :/
     
  16. Xeelot

    Xeelot

    Joined:
    Dec 28, 2010
    Posts:
    2
    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!
     
  17. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    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.
     
  18. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
  19. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    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.
     
  20. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    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.