Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Kevin__h · Apr 07, 2016 at 12:39 PM · guiguilayoutlabelareaoverlapping

GUI labels and buttons overlapping | how can I fix this?

So I am using a list of GUILayout labels and buttons. If I don't use an area it works perfect, the labels and buttons are displayed below each other (in the top left corner, but I want them to be in the middle of the screen) but when I use an area they all use the same position and just overlap each other. If anyone could help me (please don't make it too hard, I am still a noob in programming :) ), I would really appreciate it.

 void OnGUI(){
     
             Event e = Event.current;
             if (inputManager != null) {
     
                 for (int i = 0; i < inputManager.Count; i++) {
     
                     GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
                     GUILayout.BeginHorizontal ();
                     GUILayout.Label (inputManager [i].keyName, labelStyle);
     
                     if (GUILayout.Button (inputManager [i].key, keyStyle)) {
                     
                         key = i;
                         change = true;
     
                     }
     
                     GUILayout.EndHorizontal();
                     GUILayout.EndArea ();
                     }
         }

This is part of the code I use for customizable controls.

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
Best Answer

Answer by saschandroid · Apr 07, 2016 at 01:38 PM

I don't use the legacy gui, but I guess you have to put Area and Horizontal outside the for-loop:

 GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
 GUILayout.BeginHorizontal ();
 for (int i = 0; i < inputManager.Count; i++) 
 {
     GUILayout.Label (inputManager [i].keyName, labelStyle);  
     if (GUILayout.Button (inputManager [i].key, keyStyle)) 
     {
         key = i;
         change = true;  
     }
  }
 GUILayout.EndHorizontal();
 GUILayout.EndArea ();


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 Kevin__h · Apr 07, 2016 at 03:33 PM 0
Share

Thanks, this works ... I feel so stupid now for not thinking about that myself :P But do you know how I can get them under each other but with the boxes next to the label? Because if I use BeginHorizontal everything will be next to each other on a Horizontal line (obviously) and if I use Vertical everything will be under each other (again obvious) but I want my boxes next to the labels. Anyways much thanks for the suggestion it helped a lot :D

avatar image saschandroid Kevin__h · Apr 07, 2016 at 07:22 PM 0
Share

Like this?

  GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
  GUILayout.BeginHorizontal ();
  for (int i = 0; i < input$$anonymous$$anager.Count; i++) 
  {
      GUILayout.BeginVertical();
      GUILayout.Label (input$$anonymous$$anager [i].keyName, labelStyle);  
      if (GUILayout.Button (input$$anonymous$$anager [i].key, keyStyle)) 
      {
          key = i;
          change = true;  
      }
      GUILayout.EndVertical();
   }
  GUILayout.EndHorizontal();
  GUILayout.EndArea ();

avatar image Kevin__h saschandroid · Apr 07, 2016 at 08:33 PM 0
Share

This will put the buttons below the labels ins$$anonymous$$d of next to it but just switch horizontal and vertical and it's exactly what I need :D Thank you very much!

avatar image
0

Answer by CaJerry87 · Dec 20, 2016 at 07:46 AM

Look athe the images and itll help you with your Custom Inspector Layout http://answers.unity3d.com/answers/1288008/view.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Fade out GUILayout Area? 1 Answer

Additional parameters for GUILayout.Label 1 Answer

GUI.label overlapping text 1 Answer

How do I fix my GUILayout.Button 2 Answers

GUILayout Icon + Text 3 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