Search Unity

Use GUI.enable function to only enable certain buttons in a selection grid.

Discussion in 'Immediate Mode GUI (IMGUI)' started by Scrankin, Jun 19, 2015.

  1. Scrankin

    Scrankin

    Joined:
    Jun 19, 2015
    Posts:
    2
    I have 2 selection grids set up like this:
    Code (CSharp):
    1. private int classSelection
    2. private string[] classSelectionNames = new string[] { "Mage", "Warrior", "Archer", "Rogue", "Exploiter", "Crusader", "Priest", "Necromancer"};
    3. private string[] raceSelectionNames = new string[] {"Human", "Orc", "Dwarf", "Gnome", "Elf", "Beast"};
    4.  
    5. classSelection = GUI.SelectionGrid (new Rect (Screen.width - 450, 50, 400, 200), classSelection, classSelectionNames, 4);
    6. raceSelection = GUI.SelectionGrid (new Rect (50, 50, 400, 200), raceSelection, raceSelectionNames, 3);
    7.  
    I would like for certain races to only be capable of choosing certain classes. For example, a human could only choose to be a warrior, archer, rogue, crusader and priest. I was wanting to use the GUI.enabled function because it looks cool how it greys the buttons out, but I cannot figure out how to use it with the selection grid. If anyone could provide help or a suggestion that would be most appreciated! Thanks!
     
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Hey there,

    The SelectionGrid is one object. It's either all on or all off. You can do the math and just making your own grid and disable individual options. It's pretty much just two for loops drawing buttons.

    Cheers,
     
  3. Scrankin

    Scrankin

    Joined:
    Jun 19, 2015
    Posts:
    2
    That makes sense. I had the loops in mind, was just seeing if there was a way of making it easy on myself!

    Thanks!