public void MakePotion() { PotionScriptableObject potionToCraft = ListOfPotions.instance.GetPotionToCraft(); if (!potionToCraft || potionToCraft.amountOfPotion <= 0) { Debug.Log("Already crafted"); return; } if (Inventory.instance == null) { Debug.LogError("No inventory was assigned in craftPotion component"); return; } //if have enough ingredient, enable craft if (!Inventory.instance.CheckIngredients(potionToCraft)) { Debug.Log("I don't have enough ingredients"); return; } //take away ingredients for (int i = 0; i < potionToCraft.ingredients.Count; i++) { IngredientScriptableObject ingredient = potionToCraft.ingredients[i]; int amountRequired = potionToCraft.amountOfIngredients[i]; for (int j = 0; j < amountRequired; j++) { Inventory.instance.RemoveIngredient(ingredient); Debug.Log("Removed ingredient"); } } potionToCraft.amountOfPotion--; Debug.Log("I crafted a potion"); ListOfPotions.instance.SetPotionToCraft(potionToCraft); GetComponent <AudioSource>().Play(); foreach (PotionScriptableObject p in Inventory.instance.potionsToCraft) { if (p.amountOfPotion > 0) { return; } } StartCoroutine(AllDone()); }
public void RemoveIngredient(IngredientScriptableObject ingredient) { List <Item> it = itemList; for (int i = itemList.Count - 1; i >= 0; i--) { if (ingredient == it[i].ingredient) { Debug.Log(it[i].ingredient._name + "was removed from inventory!"); if (it[i].amount <= 1) { itemList.Remove(it[i]); //Destroy(i.gameObject); } else { it[i].amount--; } } } }