How to do Menu and Submenu UI - Hide/Collapse

Hi friends,

I would like to do an app with some UI elements as menus and buttons for the interaction.
Say, I have 4 menus and each menu has got some submenu buttons. When each menu is clicked, need to show those submenus under the clicked menu. When I choose the next menu, show its sub menus and hide the previous menu’s sub items. (Menus are not hidden only the submenus are hidden - Like ‘hide/collapse type of menu’

Let me attach a image of what how I expect…
Please guide me how to do it?

Thanks
Jeeva

48468-menu.jpg

Well, just need to create a boolean that you will handle your menu expandable state to true / false depending.
Then create a C# script and attach it to any gameobject of your scene:

For example:

using UnityEngine;
using System.Collections;

public GUITexture menu1 = null;
public GUITexture submenu1 = null;
public GUITexture submenu2 = null;
       
private bool menu1Expanded = false;
        
void OnGUI()
{
        if (GUI.Button(new Rect(10, 10, 120, 50), menu1))
    	{
    		menu1Expanded = !menu1Expanded;
    		// do you menu1 stuff
    	}
    	
    	if(menu1Expanded)
    	{
    		 if (GUI.Button(new Rect(10, 60, 50, 50), submenu1))
    		{
    			
    			// do you submenu1 stuff
    		}
    		
    		 if (GUI.Button(new Rect(60, 60, 50, 50), submenu2))
    		{
    			
    			// do you submenu2 stuff
    		}
    	}
}

What was the result?