Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Paul Ferris · Oct 07, 2013 at 06:17 AM · guiresolutionbuttonscompatibility

Scaling the space between GUI elements

I have a stack of buttons aligned together in a menu, but unfortunately they don't appear the same at different resolutions. Normally, there is between 1/2-1/4 centimetre of space between each button, but at <1920*1080 they grow closer and begin to overlap.

I've tried to use FlexibleSpace and padding, but sadly neither of them have worked.

Code sample:

 #pragma strict
 
 var customButton : GUIStyle;
 var customButton2 : GUIStyle;
 var customButton3 : GUIStyle;
 var customButton4 : GUIStyle;
 //private var rctOff : RectOffset;
 
 function Start(){
 
 }
 
 function OnGUI () {
     if(GUI.Button (Rect(Screen.width*0.015625, Screen.height*0.014286, 75, 25), "Sandbox", customButton)){
         Application.LoadLevel("gameDemo");
     };

    /*GUILayout.BeginArea(Rect(Screen.width*0.015625, Screen.height*0.013, 75, 20));
 GUILayout.EndHorizontal();
 GUILayout.EndVertical();
 GUILayout.FlexibleSpace();
 GUILayout.EndHorizontal();
 GUILayout.EndVertical();
 GUILayout.EndArea();*/
     
     if(GUI.Button (Rect(Screen.width*0.015625, Screen.height*0.052631, 75, 25), "Multiplayer", customButton2)){
         Application.LoadLevel("");
     };
     //GUILayout.FlexibleSpace();
     if(GUI.Button (Rect(Screen.width*0.015625, Screen.height*0.09091, 75, 25), "Options", customButton3)){
         //Application.LoadLevel("");
     };
     //GUILayout.FlexibleSpace();
     if(GUI.Button (Rect(Screen.width*0.015625, Screen.height*0.12987, 75, 25), "Exit", customButton4)){
         System.Diagnostics.Process.GetCurrentProcess().Kill();
     };
     GUI.skin.button.padding.top=20;
 }


Pictures: 1080p - Even spacing, 480p, crowded

sidebysidecomparison.png (509.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by YoungDeveloper · Oct 07, 2013 at 06:25 AM

One thing you could do, is not calculate button size from Screen.width and height, but instead use constant numbers.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Paul Ferris · Oct 07, 2013 at 07:42 AM 0
Share

I'm not, though. The screen width/height things are positional.

avatar image YoungDeveloper · Oct 07, 2013 at 08:24 AM 0
Share

Oh, yea i noticed, but it's still the case, because the buttons base position becomes so small that it overlaps one another. Try this, didn't test it though..

 function OnGUI () {
 float a = Screen.height*0.014286;
 if(GUI.Button (Rect(Screen.width*0.015625, a, 75, 25), "Sandbox", customButton)){
 Application.LoadLevel("gameDemo");
 };
 
      if(GUI.Button (Rect(Screen.width*0.015625, a+25, 75, 25), "$$anonymous$$ultiplayer", customButton2)){
     Application.LoadLevel("");
     };
     //GUILayout.FlexibleSpace();
     if(GUI.Button (Rect(Screen.width*0.015625, a+50, 75, 25), "Options", customButton3)){
     //Application.LoadLevel("");
     };
     //GUILayout.FlexibleSpace();
     if(GUI.Button (Rect(Screen.width*0.015625, a+75, 75, 25), "Exit", customButton4)){
     System.Diagnostics.Process.GetCurrentProcess().$$anonymous$$ill();
     };
     GUI.skin.button.padding.top=20;
     }
avatar image Paul Ferris · Oct 07, 2013 at 10:52 AM 0
Share

Unity is telling me to add a semicolon after "float a = Screen.height*0.014286;". How should I fix this?

avatar image
0

Answer by Jamora · Oct 07, 2013 at 09:09 AM

A GUI.SelectionGrid should keep the spaces constant. You'll have to play around with GUIStyles to get the spacing between them correct, but once that's set it shouldn't change when the resolution changes.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

loop GUI Buttons doesn`t respond 0 Answers

Is this the correct way to scale my GUI? 1 Answer

GUI Resolution Ajust 1 Answer

Android screen size script not working 1 Answer

Problems while setting up buttons on the GUI 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges