Could someone please tell me how to assign values to the buttons when using a GUI.SelectionGrid. I’m using the code from Unity - Scripting API: GUI.SelectionGrid. What I want to do is when I click the 1st button an attack will happen, click the 2nd button and the characters health will be be full again and so on. I have the selection grid on screen but cant figure out how to do actions when the button pressed. The code from the website is -
public int selGridInt = 0;
public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};
void OnGUI() {
selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2);
}
I would guess that selection grid is not what you really want
with the selgrid, you cant use the same button twice in a row, so no attack attack attack etc
hpjohn is correct because OnGUI will be call several times in a frame kinda like the Update function so if you have your selection grid 0 int active it will stay active as long as the button is selected. You could do a switch statement or use booleans for what your trying to do.
Thanks, I was trying to change change if (selStrings == 0), silly me . I have little to no experience with switch cases so i will use the boolean. But how do I use the boolean with it properly? My if block is this