Search Unity

help help

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

  1. giulioandrea

    giulioandrea

    Joined:
    Feb 16, 2006
    Posts:
    72
    quick question:

    I would like to build a menu with multiple choices and sub menus for each choice...
    I am happy to use buttons on the screen, which appear whenever the first button (choice) is pressed.

    Layout ----------------------> Tilt------- ------------> Shade
    |5|_____________________|45|
    |3|_____________________|0|
    _______________________|-45|_____________ |down|
    ________________________________________|up|

    How to do this???

    I tried some coding with the if (button) {if (button)} idea in mind, see below.
    Unfortunately nothing happens.

    Deadline is approaching, any help?
    Super thanks
    G.



    Code (csharp):
    1. var mySkin : GUISkin;
    2.  
    3. //all levels names
    4. private var all_names1 = [Layers.op1, Layers.op2, Layers.op3,Layers.op4, Layers.op5, Layers.op6];
    5. private var all_names2 = [Layers.op1, Layers.op2, Layers.op3,Layers.op4, Layers.op5, Layers.op6];
    6.  
    7. //the starting selection
    8. private var names = [Layers.op1,Layers.others ];
    9.  
    10. //offset for buttons layout
    11. private var L1 = 0;
    12. private var L2= 120;
    13. private var L3 = 240;
    14.  
    15. function OnGUI() {
    16. //when esc is pressed the interface opens
    17. if (Input.GetKey ("escape") ) {
    18.  
    19.     GUI.skin = mySkin; 
    20.     GUI.Box (Rect (10+L1,10,150,125+20), "Layout Selection");
    21.    
    22.     //when I press on this button another butto is shown
    23.     if (GUI.Button (Rect (25+L1,20+45,120,20), "5 Mullions")) {
    24.  
    25.     GUI.Box (Rect (10+L2,10,150,125+20), "Tilt Selection");
    26.  
    27.     //when I press on this button another button is shown
    28.     if (GUI.Button (Rect (25+L2,20+45,120,20), "+45")) {
    29.  
    30.         GUI.Box (Rect (10+L3,10,150,125+20), "Blinds");
    31.  
    32.         if (GUI.Button (Rect (25+L3,20+45,120,20), "Open")) {
    33.         names[0] = all_names1[0];
    34.         }
    35.         if (GUI.Button (Rect (25+L3,20+45,120,20), "Deployed")) {
    36.         names[0] = all_names2[0];
    37.         }
    38.     }  
    39.  
    40.  
    41. //five mullions
    42.     }
    43.  
    44.     if (GUI.Button (Rect (25,155+20,120,20), "Main Menu")) {
    45.     Application.LoadLevel("menu");
    46.     }
    47.    
    48. camera.cullingMask = Layers.CreateInclusiveMask(names);
    49. //when esc is presse
    50.     }
    51. //function
    52. }
    53.  
    54.  
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    The if(Button()) is only true on the MouseUp Event. Try creating a bool to store if the second level is open, and which 'id' it if, then you can just enumerate a list of second level options which contain buttons to open third level options, in the same way as the second.
     
  3. giulioandrea

    giulioandrea

    Joined:
    Feb 16, 2006
    Posts:
    72