I have a method ListItems() witch i want to be updated whenever I open the Inventory for my game in Unity. Whenever I try this I get the error: member InventoryManager.ListItems() cannot be accessed with an instance reference; qualify it with a type name instead
None of these methods are static, so I'm a bit confused here...
ListItems() :
public void ListItems()
{
foreach(var item in Items)
{
GameObject obj = Instantiate(InventoryItem, ItemContent);
var itemName = obj.transform.Find("Item/ItemName").GetComponent<Text>();
var itemIcon = obj.transform.Find("Item/ItemIcon").GetComponent<Image>();
itemName.text = item.itemName;
itemIcon.sprite = item.icon;
}
}
Update() from a different class:
public GameObject inventory;
public InventoryManager i;
public void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
InventoryManager.GetComponent<InventoryManager>().ListItems();
inventory.gameObject.SetActive(!inventory.gameObject.activeSelf);
}
}