Craft System

Hi, guys, how are you?
I’m a bit in trouble, and I assume I was stuck in it a few days, so I decided to ask for help.
I’m doing a craft system where the player pushes a button to make the new item, in that item he has an array of items that is the price to craft, ie a shovel would need (wood and stone).
My code works partially, but I need to verify that the player has the 2 items in his inventory, in which case he only checks one item.
Would anyone have any suggestions on how to improve this system?

thank you in advance, any and all help. :slight_smile:

Prints

4055941--352909--upload_2019-1-2_17-8-5.png

Cost of the item, there are 2 linked items and the intention is to compare if it has these 2 items in the inventory.

4055941--352918--upload_2019-1-2_17-10-3.png

Void CheckHaveItem(){

        for (int i = 0; i < itemToSlot.cost.Length; i++)
        {

            var checkInventory = buildItems.inventory.slot.Where(x => x.itemToSlot != null).Where(x => x.itemToSlot.Id == itemToSlot.cost[i].Id);

            foreach (var item in checkInventory)
            {
                //Enable and disable button craft
     
            }
        }

}

4055941--352912--upload_2019-1-2_17-8-25.png
4055941--352915--upload_2019-1-2_17-8-49.png

Someone ? :frowning:

Hi @PedroMBP

What actually isn’t working? It would be easier for anyone to help, if the question was clear…

This sentence…

“I need to verify that the player has the 2 items in his inventory, in which case he only checks one item.”

deosn’t make much sense.

You can loop the items in your crafting “recipe” and then do a contains check for each of these in your inventory, if any of these is missing, return false.

Only if every ingredient is found return true from your CheckHaveItem.