Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

sub menus

Discussion in 'Immediate Mode GUI (IMGUI)' started by giulioandrea, Jul 14, 2008.

  1. giulioandrea

    giulioandrea

    Joined:
    Feb 16, 2006
    Posts:
    72
    this is meant to be another example of my menu system.

    this is a simple implementation, if you click on button first, then second opens.
    if you click on second then third opens...

    but it does nothing.
    what's wrong??
    thanks
    G.



    Code (csharp):
    1. var L1 = 0;
    2. var L2 = 100;
    3. var L3 = 200;
    4.  
    5. function OnGUI() {
    6.  
    7. if (GUI.Button (Rect (25+L1,20+45,120,20), "first")) {
    8.  
    9.  
    10. if(GUI.Button (Rect (25+L2,20+55,120,20), "second")) {
    11.    
    12.     GUI.Button (Rect (25+L3,20+65,120,20), "third");
    13.     }
    14.  
    15. }
    16. }
    17.  
    18.  
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    GUI.Button only returns true the one frame it's clicked on. You'd probably want to store the result of a click in a variable so you can use that indefinitely.

    Code (csharp):
    1. private var button1clicked = false;
    2.  
    3. function OnGUI () {
    4.    if (GUI.Button (Rect (25+L1,20+45,120,20), "first")) {
    5.       button1clicked = true;
    6.    }
    7.    if (button1clicked) {
    8.       if (GUI.Button (Rect (25+L2,20+55,120,20), "second")) {
    9.          //etc.
    10.       }
    11.    }
    12. }
    --Eric
     
  3. giulioandrea

    giulioandrea

    Joined:
    Feb 16, 2006
    Posts:
    72
    you saved me.
    it is exactly what I was looking for!
    thanks
    G>

    :oops: :D :D