void Start() { boxCollider2D = GetComponent <BoxCollider2D>(); //furnace needs this as a reference theFurnace = GameObject.Find("Furnace").GetComponent <FurnaceScript>(); //also spawning theSpawning = GameObject.Find("SpawningPoint").GetComponent <SpawningScript>(); //the ingredients should fly towards this, if correct target = null; theChangeScene = GameObject.Find("Canvas").GetComponent <ChangeSceneScript>(); theMoney = GameObject.Find("Money").GetComponent <MoneyScript>(); theSPF = GameObject.Find("SpawningFoodLayer").GetComponent <SpawningFoodLayerScript>(); theSPF.spawnfoodlayer();// foodlayerclone = GameObject.Find("FoodLayer(Clone)"); theNextRecipe = GameObject.Find("NextRecipeButton").GetComponent <NextRecipeScript>(); theGameMaster = GameObject.Find("GameMaster").GetComponent <GameMasterScript>(); }
// Update is called once per frame void Update() { //MoveFoodLayer(); //the "change " boolean variable is called when a recipe is finished, // in order to allow our current foodlayer to disappear // and a new one to take its place if (change == true) { //rename our object so that it doesn't interfere with other similar objects' functionality if (gameObject.name.EndsWith("(Clone)")) { gameObject.name = gameObject.name.Substring(0, gameObject.name.Length - 7);//remove (clone) from string } transform.position = Vector2.MoveTowards(transform.position, movetoward.transform.position, Time.deltaTime * 03); theSPF.spawnfoodlayer(); if ((gameObject.transform.position.x == movetoward.transform.position.x) && (gameObject.transform.position.y == movetoward.transform.position.y)) { StartCoroutine("ScaleO"); //Destroy(gameObject); change = false; } } else if (theNextRecipe.gamepause)// do not show anything if we aren't prepared to handle the next customer! { //Debug.Log("rendred null"); if (gameObject.name.EndsWith("(Clone)")) { renderers[renderers.Count - 2].sprite = null; } } else { //Debug.Log("spriterenderedfully"); if (gameObject.name.EndsWith("(Clone)")) { renderers[renderers.Count - 2].sprite = SpriteLayerBase(target.GetComponent <FurnaceScript>().recipe.name); } } }
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; }