• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

124 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 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

Invisible BeginScrollView thumb 0 Answers

Can't add a GUI in C#?? 1 Answer

How do I prevent "Argument Exception: Getting control 1's position in a group with only 1 controls when doing repaint" in OnGUI function of my CustomPropertyDrawer? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges