public void itemCollected(string itemName) { if (ingredientsDict.ContainsKey(itemName)) { ingredientsDict[itemName] = true; //display ingredients & state string ing = IngredientsToText(); recipeController = uiRecipe.GetComponent <UIRecipeController>(); GetComponent <AudioSource>().Play(); recipeController.ChangeText(ing); //check if all ingredients are collected bool collectedAllFlag = true; foreach (KeyValuePair <string, bool> entry in ingredientsDict) { if (entry.Value == false) { collectedAllFlag = false; } } if (collectedAllFlag) { allIngredientsCollected = true; showEndLevelMessage(); } } }
/*Set Recipe for this level*/ public void setRecipe(string potionName, string[] ingredients) { if (recipeController != null) { this.ingredients = ingredients; this.potionName = potionName; //no ingredients are collected in the beginning allIngredientsCollected = false; //create dict to manage state of ingredient: picked up = True, not picked up = False ingredientsDict = new Dictionary <string, bool> (); for (int i = 0; i < ingredients.Length; i++) { string tmp = ingredients[i]; ingredientsDict[tmp] = false; } //display ingredients & state recipeController.ChangeText(IngredientsToText()); } }