public void craftItem(string productName) { CraftingRecipe myRecipe = playerInventoryScript.findRecipeWithProductName(productName); bool canBuy = true; for (int i = 0; i < myRecipe.materialNames.Length; i++) { if (playerInventoryScript.findItemQuantityInPlayerInventory(myRecipe.materialNames [i]) < myRecipe.materialQuantities [i]) { canBuy = false; break; } } if (canBuy) { playerInventoryScript.addObjectToPlayerInventory(myRecipe.productQuantity, myRecipe.productName, myRecipe.productDisplayName, false, Vector3.zero); for (int i = 0; i < myRecipe.materialNames.Length; i++) { playerInventoryScript.takeItemFromPlayerInventory(myRecipe.materialQuantities [i], myRecipe.materialNames [i]); } } }