Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
Crafting System, Removing Items doesn't remove items

I'm working on an Inventory System with a Crafting System. When I first made it it was working, it crafted items if the player had enough resources in Inventory to craft it and then removed the items that were used to craft the item and add the item we just crafted. But now the part where it should delete items that were used to craft the object doesn't work.

Function where everything starts:

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;

}

RemoveIngredientsFromInventory function:

//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);

    }

}

RemoveItems function:

//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);

    }

}

and then RemoveItem function (i have it as a different function because I need to remove the item from the list and then invoke the changes so it's displayed and then I don't have to write it every time I just have to call the function):

//Remove Item function
public void RemoveItem(Item item) {

    //remove item from IntentoryItemList list
    InventoryItemList.Remove(item);
    onItemChange.Invoke();

}

I tried to write something into console inside the RemoveItem function and it wrote it into console but for some reason, it didn't remove the ingredients.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda