- Home /
How do you check one box in a GUI.SelectionGrid?
I am currently working on an inventory system. It it working pretty good and recognizes what I am collecting. I have now moved on to actually using the item. My theory was, when a box in the inventory is selected, a comparison is made. Unity will try to see if the texture in the box matches any texture in a master list of textures. If it matches wood then it must be wood {do something lol}. My problem is, I can't figure out how to check one box when using GUI.SelectionGrid. Unity keeps trying to check every box, so it will tell me that box 4 has wood (when it doesn't) because I have wood somewhere else in the inventory. Please Help!!
Answer by Spinnernicholas · Apr 06, 2015 at 05:33 PM
The SelectionGrid function returns the index of the selected element.
So if you pass it an array like this: {wood, stone, water, gold}
a return of 0 means wood is selected, 3 means gold, etc.
int selection = GUI.SelectionGrid(.......);
if(selection == 0)
{
//You have selected wood
}
//or
switch(selection)
{
case 0:
//wood
break;
case 1:
//stone
breal;
//...........
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613192221im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Highlighting Individual Tile Squares 0 Answers
Place Inventory Into GUI Button Grid 3 Answers
Algorithm for Finding Shapes on a Grid 1 Answer
Making an Inventory (Basics) 2 Answers
GUI grid of buttons issue. 1 Answer