public void SelectItemFromInventory(GameItem item) { for (int i = _inventory.Count - 1; i >= 0; i--) { if (_inventory[i] == item) { if (!item.selected) { if (_selectedItem != null) { DeselectItemFromInventory(_selectedItem); //deselected currently selected item foreach (Transform child in actionMenuContent.transform) { GameObject.Destroy(child.gameObject); } } _selectedItem = item; item.selected = true; SelectedItemButton.CreateComponent(selectedItemField, item); selectedItemField.SetActive(true); CloseInventory(); } } } }
public static SelectedItemButton CreateComponent(GameObject where, GameItem gameItem) { SelectedItemButton actionBtn = where.AddComponent <SelectedItemButton>(); Property containsProp = gameItem.GetProperty("contains"); if (containsProp != null) { where.GetComponentInChildren <Text>().text = gameItem.dbItem.description + "[" + containsProp.value + "]"; } else { where.GetComponentInChildren <Text>().text = gameItem.dbItem.description; } actionBtn._gameItem = gameItem; return(actionBtn); }