Estoy trabajando en un sistema de inventario con un sistema de elaboración. Cuando lo hice por primera vez, funcionaba, creaba elementos si el jugador tenía suficientes recursos en el inventario para crearlo y luego eliminaba los elementos que se usaron para crear el elemento y agregaba el elemento que acabamos de crear. Pero ahora la parte donde debería eliminar los elementos que se usaron para crear el objeto no funciona.
Función donde todo comienza:
public bool CraftItem() { //if CanCraft returned false we return false from function if(!CanCraft()) { return false; } //start crafting ParentCraftingSlot.StartCrafting(); //call RemoveIngredientsFromInventory to remove item from inventory RemoveIngredientsFromInventory(); //return true return true; }Función RemoveIngredientsFromInventory:
//remove ingredients from inventory //because we don't want to have the ingredients after we crafted something private void RemoveIngredientsFromInventory() { foreach(Ingredient ingredient in ingredients) { //call RemoveItems function with ingredient item and amount Inventory.instance.RemoveItems(ingredient.item, ingredient.amount); } }Función RemoveItems:
//RemoveItems from inventory public void RemoveItems(Item item, int amount) { //loop through amount of items for(int i = 0; i < amount; i++) { //remove item from Inventory RemoveItem(item); } }y luego la función RemoveItem (lo tengo como una función diferente porque necesito eliminar el elemento de la lista y luego invocar los cambios para que se muestre y luego no tengo que escribirlo cada vez que solo tengo que llamar a la función) :
//Remove Item function public void RemoveItem(Item item) { //remove item from IntentoryItemList list InventoryItemList.Remove(item); onItemChange.Invoke(); }Traté de escribir algo en la consola dentro de la función RemoveItem y lo escribió en la consola pero, por alguna razón, no eliminó los ingredientes.