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 orkungo · Oct 02, 2017 at 04:02 PM · guiguilayoutguilayout.button

How can I create nested buttons ?

Hi,

I would like to create nested buttons with GUILayout.Button.

My scenario is as following:

I have a main button, whenever I click it starts the game with preset settings (1). Also I have inner buttons, if I click it changes some of the settings of a game but does not start anything(2).

alt text

I would like to solve this issue with scripting fx. GUILayout.Button()

Any ideas?

draw.png (15.4 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
5

Answer by BlakeSchreurs · Oct 02, 2017 at 04:32 PM

I know you may not like this, but I'm going to encourage you to re-think your design to something a little more traditional. People accurately hit buttons about 95% of the time, which means about 1 out of 20 times someone will take an unintended action with this layout (as opposed to hitting a margin and doing nothing). Having a big start button above the three configure buttons will be a much more user-friendly design than a button-in-button design.alt text


rect4136-9.png (3.4 kB)
Comment
Add comment · Show 1 · 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 orkungo · Oct 02, 2017 at 09:21 PM 0
Share

Thank you for the answer, it is true your approach is more user-friendly.

It is always the best to evaluate :)

avatar image
1

Answer by YoucefB · Oct 02, 2017 at 06:17 PM

You can disable GUI interaction with the Main-Button when the mouse is over any of the other buttons.

Here is an exemple:

 void OnGUI(){
             
         Event e = Event.current;
 
             Rect r = new Rect (0,0,200,200); // play button rect
             Rect s1 = new Rect (20,80,60,20); // setting 1 button rect
             Rect s2 = new Rect (120,80,60,20);  // setting 2 button rect
 
         // check if mouse is over any of the settings buttons, if so disable the gui for the Play button
         foreach (Rect rect in new Rect[]{s1,s2})
             if (rect.Contains(e.mousePosition))
             GUI.enabled = false;
         
         if (GUI.Button (r,"Play")){ 
                 Debug.Log ("Play was Clicked");
             }
 
         GUI.enabled = true; // re-enabling the gui for the other buttons
 
         if (GUI.Button (s1,"setting 1")){
                 Debug.Log ("setting 1 was Clicked");
         } 
         if (GUI.Button (s2,"setting 2")){
                 Debug.Log ("setting 2 was Clicked");
         }
 
         }


Comment
Add comment · Show 4 · 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 orkungo · Oct 02, 2017 at 06:38 PM 0
Share

Thank you but I'm developing a mobile game. Your solution works for the mouse interactions however I need something for touch..

avatar image YoucefB orkungo · Oct 02, 2017 at 06:47 PM 0
Share

this should work for any platform including mobile.

avatar image orkungo YoucefB · Oct 02, 2017 at 06:50 PM 0
Share

How would I hover on mobile? That was the reason I wrote below comment.

Show more comments

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

123 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

GUI does not contain a definition for `skin' ? 1 Answer

How can i change the color of GUILayout elements? such as buttons 1 Answer

How to disable horizontal scrollbar in GUILayout scroll view? 3 Answers

Additional parameters for GUILayout.Label 1 Answer

Using treeview OnGUI with GUIlayout 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