public void OnMouseDown() { //Debug.Log("onmousedown"); //do not allow clicking if the game is paused/disabled if (theNextRecipe.gamepause) { return; } //create a layered-food if we don't already have one if ((foodlayerclone = GameObject.Find("FoodLayer(Clone)")) == false) { Debug.Log("foodlayerclone is false"); theSPF.spawnfoodlayer(); foodlayerclone = GameObject.Find("FoodLayer(Clone)"); Debug.Log("foodlayerclone: " + foodlayerclone); } theFoodLayer = GameObject.Find("FoodLayer(Clone)").GetComponent <FoodLayersScript>(); //get the correct base-sprite //foodlayerclone.GetComponent<FoodLayersScript>().renderers[3].sprite = theFoodLayer.SpriteLayerBase(theFurnace.recipe.name); //theNextRecipe.gamepause = true; theNextRecipe.gamepause = false; //rename our object so that it is usable within recipes //(remove (clone) from string) if (gameObject.name.EndsWith("(Clone)")) { gameObject.name = gameObject.name.Substring(0, gameObject.name.Length - 7); } else { Debug.Log("cannot delete ingredient's substring"); return; } //add to current recipe theFurnace.current_recipe.Add(gameObject.name); bool ingredientisonthelist = false; //remove from the correct igredient from the numbers list int i = 0; //Debug.Log("before loops"); foreach (string checkingr in theFurnace.recipe.neededIngr) { if (checkingr == gameObject.name) { //if we have all of what we need from this ingredient, we shouldn't bother dealing with it if (theFurnace.usable_number_of_ingredients[i] == 0) { //Debug.Log("filled ingreadient"); ingredientisonthelist = false; //add to the false theGameMaster.numberFalseClicks++; break; } // otherwise, we are going to use it in our recipe: //add to the number of correct clicks theGameMaster.numberCorrectClicks++; //assign to the correct number theFurnace.usable_number_of_ingredients[i]--; inum = i; ingredientisonthelist = true; target = GameObject.Find("Furnace"); //also, clone it as a transparent-ticked object string formrname = gameObject.name; invisivise2(formrname, gameObject); //since we have our target, we should change our sprite to something more relevant gameObject.GetComponent <SpriteRenderer>().sprite = theFoodLayer.SpriteChooseIngredient(theFurnace.recipe.name, gameObject.name); //disable text labels as well gameObject.GetComponentInChildren <TextMeshPro>().enabled = false; break; } i++; } //destroy only if it is on the list if (ingredientisonthelist == false) { //remove ingredient from the current list if not needed theFurnace.current_recipe.Remove(gameObject.name); Debug.Log("object not on list"); //rename it back to its original name //(this is a workaround for allowing only "(clones)" to move! gameObject.name += "(Clone)"; //add to the number of false clicks theGameMaster.numberFalseClicks++; } //when we destroy an object, we can instantiate the next one theSpawning.spawnallowed = true; }
//bool ingredientnumber // Update is called once per frame void Update() { theFoodLayer = null; if (GameObject.Find("FoodLayer(Clone)") == null) { return; } else //if(theFoodLayer!=null) { theFoodLayer = GameObject.Find("FoodLayer(Clone)").GetComponent <FoodLayersScript>(); gameObject.GetComponent <RecipeCheckScript>().recipeimage.enabled = false; foreach (Image imagei in gameObject.GetComponent <RecipeCheckScript>().images) { imagei.enabled = false; imagei.preserveAspect = true; imagei.GetComponentInChildren <Text>().enabled = false; } speechbubble = GameObject.Find("SpeechBubble").GetComponent <SpriteRenderer>(); speechbubble.enabled = true; } recipenote.text = null; //show the recipe only if we haven't paused/disabled the game if (theNextRecipe.gamepause == false) { //the recipe we want to make, depicted gameObject.GetComponent <RecipeCheckScript>().recipeimage.enabled = true; gameObject.GetComponent <RecipeCheckScript>().recipeimage.sprite = furnscript.recipe.recipeSprite; for (int i = 0; i < furnscript.recipe.neededIngr.Count; i++) { //if we already have all of this ingredient we don't need to show it anymore //image version gameObject.GetComponent <RecipeCheckScript>().images[i].enabled = true; speechbubble.enabled = true; //speechbubble.sprite= Resources.LoadAll<Sprite>("canteen_things")[1]; speechbubble.sprite = theGameMaster.spriteslayers["SpeechBubble_Empty"]; speechbubble.GetComponentInChildren <TextMeshPro>().enabled = false; //Debug.Log(furnscript.recipe.neededIngr[i]); gameObject.GetComponent <RecipeCheckScript>().images[i].sprite = RecipeIngredientCheckListSprite(furnscript.recipe.neededIngr[i], furnscript.usable_number_of_ingredients[i]); //text description of images RecipeIngredientDesc(furnscript.recipe.neededIngr[i], gameObject.GetComponent <RecipeCheckScript>().images[i]); gameObject.GetComponent <RecipeCheckScript>().images[i].GetComponentInChildren <Text>().enabled = true; //Debug.Log(furnscript.recipe.neededIngr.Count); //Debug.Log(furnscript.usable_number_of_ingredients.Count); } fireworkplay.Stop(); } else { //recipe finished correctly //speechbubble.sprite = Resources.LoadAll<Sprite>("canteen _ευχαριστω bubble copy")[0]; speechbubble.sprite = theGameMaster.spriteslayers["SpeechBubble_Smile"]; speechbubble.GetComponentInChildren <TextMeshPro>().enabled = true; fireworkplay.Play(); //GameObject.Find("Canvas").transform.Find("ProgressBar").GetComponent<ProgressBarScript>().currentfill++; } //destroy particles when exiting screen //OnBecameInvisible }