I have a listof strings and a list of textures, both are added/remoted simultaniously, so each item in the list is assosiated with the other in the other string.
For example, my string list might be something like this:
{"cube", "sphere", "cone"}
while my texture array will be like this:
{cubeTexture2D, sphereTexture2D, coneTexture2D}
as you can see, each one has a counterpart in the other list.
I have a selectiongrid that is based off of the texture array, so that it displays a button with each items texture. Here is the relevant code:
public void AddedItem(string idRecieved){ //function to add items to the inventory, idRecieved is the ID string from our ItemPickup script
inventoryStrings.Add(idRecieved);
inventoryButtons.Add(itemSelectedButton);
itemSelected = playerCamera.GetComponent().itemHit;
itemSelectedButton = itemSelected.GetComponent().identityButton;
}
void OnGUI(){
int selectedButton = 0;
if(isInventoryOpen)
{
Screen.lockCursor = false;
selectedButton = GUILayout.SelectionGrid(selectedButton, inventoryButtons.ToArray(), 10, GUILayout.Height(50));
Time.timeScale = 0;
playerCamera.GetComponent().enabled = false;
GetComponent().enabled = false;
}
else
{
Time.timeScale = 1;
Screen.lockCursor = true;
playerCamera.GetComponent().enabled = true;
GetComponent().enabled = true;
}
}
}
what I want, is in my void OnGUI, I want to have a variable that is equal to the string in the list that is assosiated with it's selectiongrid button. Since selectiongrid returns an int based on what button is selected, I was thinking to do something like:
public string buttonReference;
buttonReference = inventoryStrings.IndexOf(selectedButton);
But I dont think that will work.
tl;dr: I need to have buttonReference = the list item that is on the selectiongrid button the player presses.
↧