Answer the question
In order to leave comments, you need to log in
What is the correct way to call a function in a class?
Hello. I have an AddItem method in the Inventory class
public void AddItem(int id, Item item, int count)
{
items[id].id = item.id;
items[id].count = count;
items[id].itemGameObject.GetComponent<Image>().sprite = item.img;
if (count > 1 && item.id != 0)
{
items[id].itemGameObject.GetComponentInChildren<Text>().text = count.ToString();
} else
{
items[id].itemGameObject.GetComponentInChildren<Text>().text = "";
}
}
Inventory inv = new Inventory();
inv.AddItem(0, inv.items[1], 1);
public class DataBase : MonoBehaviour
{
public List<Item> items = new List<Item>();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question