public IEnumerator Dontuseboats() { foreach (GameObject AllBoats in GameObject.FindGameObjectsWithTag("boat")) { AllBoats.GetComponent <BoxCollider2D>().enabled = false; } foreach (GameObject AllBoats in GameObject.FindGameObjectsWithTag("point")) { AllBoats.GetComponent <BoxCollider2D>().enabled = false; } yield return(new WaitForSeconds(0.3f)); foreach (GameObject AllBoats in GameObject.FindGameObjectsWithTag("boat")) { AllBoats.GetComponent <BoxCollider2D>().enabled = true; } foreach (GameObject AllBoats in GameObject.FindGameObjectsWithTag("point")) { AllBoats.GetComponent <BoxCollider2D>().enabled = true; } }
IEnumerator BoatMoving(float TotalDistance) { foreach (GameObject AllBoats in GameObject.FindGameObjectsWithTag("boat")) { AllBoats.GetComponent <BoatBehavoir>().CanUse = false; } Vector2 pointtopoint = boat.transform.position; controller.Score++; _text.GetComponentInChildren <SpriteRenderer>().enabled = true; _text.text = ": " + controller.Score; while (Vector2.Distance(gameObject.transform.position, pointtopoint) >= TotalDistance && boat != null) { float speed = 30; if (Mathf.Abs(Vector2.Distance(gameObject.transform.position, pointtopoint) - TotalDistance) < 0.15f) { speed = 230; } if (frontOrBack == true) { boat.transform.position += boat.transform.TransformDirection(Vector2.up / speed); } else { boat.transform.position -= boat.transform.TransformDirection(Vector2.up / speed); } pointtopoint = boat.transform.position; yield return(new WaitForSeconds(0.0166666666666667f)); } if (boat != null) { boat.GetComponent <BoatBehavoir>().CanUse = true; } foreach (GameObject Allboeats in GameObject.FindGameObjectsWithTag("boat")) { Allboeats.GetComponent <BoatBehavoir>().CanUse = true; } if (finishPoint == true) { Particles.Emit(100); _Button.transform.position = new Vector3(0, 0, 0); string HighScore = GlobalGameSettings.GetSetting("Reset_High_Score"); if (PlayerPrefs.GetInt(controller.LevelName.ToString()) == 0) { PlayerPrefs.SetInt(controller.LevelName.ToString(), controller.Score); } if (controller.Score < PlayerPrefs.GetInt(controller.LevelName.ToString())) { PlayerPrefs.SetInt(controller.LevelName.ToString(), controller.Score); } if (HighScore == "Ja") { PlayerPrefs.DeleteKey(controller.LevelName.ToString()); _Button.GetComponentInChildren <TextMesh>().text = "Beste score: " + controller.Score.ToString(); } else { _Button.GetComponentInChildren <TextMesh>().text = "Beste score: " + PlayerPrefs.GetInt(controller.LevelName.ToString()).ToString(); } _text.text = ""; _text.GetComponentInChildren <SpriteRenderer>().enabled = false; controller.GetComponent <AudioSource>().Play(); foreach (GameObject Allboeats in GameObject.FindGameObjectsWithTag("boat")) { Allboeats.GetComponent <BoatBehavoir>().CanUse = false; } for (int i = 0; i < 300; i++) { if (boat != null) { boat.transform.position += boat.transform.TransformDirection(Vector2.up / 30); } else { break; } yield return(new WaitForSeconds(0.0166666666666667f)); } Invoke("ToScores", 2.5f); } }