- Home /
Question by
unity_6RON7wIJSBpKrg · May 28, 2020 at 11:45 PM ·
inventorylistscrafting
I'm trying to make a button that instantiates an item when you craft it
public int[] needsAmount;
public GameObject[] needs;
public GameObject craftedItem;
public GameObject player;
public Vector2 spawnPoint;
public void craft()
{
for (int i = 0; i > needs.Length; i++)
{
for(int j = 0; j > player.GetComponent<PlayerControl>().inventory.Length; j++)
{
if(player.GetComponent<PlayerControl>().inventory[j].GetComponent<Object>().id == needs[i].GetComponent<Object>().id &&
player.GetComponent<PlayerControl>().inventory[j].GetComponent<Object>().quantity >= needsAmount[i])
{
player.GetComponent<PlayerControl>().inventory[j].GetComponent<Object>().quantity -= needsAmount[i];
Instantiate(craftedItem, spawnPoint, transform.rotation);
}
}
}
}
Comment
Answer by unity_6RON7wIJSBpKrg · May 28, 2020 at 11:51 PM
I'm comparing 3 lists of objects, one with the items needed for the craft and other with the amount of that item needed. The other list is the inventory of the player, it has to check if the item id is the same, and if you have enough quantity of that item. I don't really get why it's not working
Your answer
Follow this Question
Related Questions
How do I retrieve an item from a list? 1 Answer
Inventory String error 1 Answer
Inventory List Crafting HELP 0 Answers
Crafting items. Best way to do it? 0 Answers