- Home /
 
Actually do something with GUI selection grid
How do I get a selection grid to actually to something. Like how would I clicked which button on the grid has been pressed then do something.
Here is my code so far
 var gridId : int;
     var gridRowX : int;
     var menueGrid : String[] = ["Health", "Crafting", "Melee", "Guns"];    
     
     
     
     var gridXPos : int; // temporaray;
     var gridYPos : int; // temporaray;
     var gridXSize : int;
     var gridYSize : int;
     
     
     
     function OnGUI(){
         GUI.skin = mySkin;
         if(menueActive){
             GUI.BeginGroup(Rect(xPos,yPos,500,300), mySkin.GetStyle("base"));
                 GUI.SelectionGrid(Rect(gridXPos,gridYPos,gridXSize, gridYSize),gridId, menueGrid, gridRowX,mySkin.GetStyle("grid1"));
                 
                 Debug.Log(gridId);
         
             GUI.EndGroup();
         }
     
     }
 
              example :
 public int selGridInt = 0;
 public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};
     
 void OnGUI()
 {
      selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 2);
         
      GUILayout.Box(selStrings[selGridInt]) ;
 }
 
                 I tried your example. selGridInt dose not change, it just stays 0
opps, never $$anonymous$$d it dose. I just did not look carefully enough. Turns out Selection Grid returns a integer.
Answer by johnnymoha · Jul 10, 2013 at 01:28 AM
 var selGridInt : int = 0;
 var selStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];
 
 function OnGUI () {
     selGridInt = GUI.SelectionGrid (Rect (25, 25, 100, 30), selGridInt, selStrings,2); 
     //selGridInt will change based on your selected box
 
    if (selGridInt==whatever){
       Debug.Log("stuff here");
    }
 }
 
 
              Thanks to the both of you. If I would have read the API more carefully I would have realized that selection grid returns an int that needs to be stored in a varible.
how can i get a different script on a different object to know which one?
Your answer
 
             Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
GUI.Toggle to only send one action, not repeated 1 Answer
Trouble getting GUI phone to open/close 1 Answer
3 sets of button activations GUI 1 Answer