private void Update() { if (!isGameStarted && !DialogueAnimator.GetBool("isOpen") && score > scoreOnFinish && !isEndless) { isGameOver = true; SceneManager.LoadScene("Beach"); return; } if (!isGameOver) { if (Input.anyKey && !isGameStarted && !DialogueAnimator.GetBool("isOpen")) { isGameStarted = true; playerMotor.StartRunning(); cameraMotor.StartFollowing(); compMotor.StartRunning(); if (Settings.isMusicOn.Value) { audioPlayer = GameObject.FindGameObjectWithTag("SoundController"); Music music = audioPlayer.GetComponent <Music>(); music.changeMusic(SceneManager.GetActiveScene()); } } } if (isGameStarted) { score += Time.deltaTime; scoreText.text = score.ToString("0"); if (!isEndless) { if (score > scoreOnFinish) { isGameStarted = false; isGameOver = true; playerMotor.StopRunning(); cameraMotor.StopFollowing(); compMotor.StopRunning(); DialogueAnimator.SetBool("isOpen", true); endCutscene.Begin(); if (Settings.isMusicOn.Value) { StartCoroutine(AudioController.FadeOut(musicPlayer, 0.5f)); } } else if (score > 40) { informationText.text = "The ice has all melted away!"; } else if (score > 30) { informationText.text = "The mountains are collapsing!"; } else if (score > 12) { informationText.text = "Careful! The water is toxic."; } else if (score > 8) { informationText.text = "Swipe up to jump"; } else if (score > 3) { informationText.text = "Swipe down to slide"; } else if (score > 0) { informationText.text = "Swipe to move"; } } else { informationText.text = null; } } }
/* This method is run every frame */ private void Update() { // Goes to the next level in the story if the user has met the conditions if (!isGameStarted && !DialogueAnimator.GetBool("isOpen") && score > 120 && !isEndless) { isGameOver = true; SceneManager.LoadScene("Forest"); return; } // Starts the game after the user has run through the initial text. if (!isGameOver) { if (Input.anyKey && !isGameStarted && !DialogueAnimator.GetBool("isOpen")) { isGameStarted = true; playerMotor.StartRunning(); cameraMotor.StartFollowing(); compMotor.StartRunning(); if (Settings.isMusicOn.Value) { audioPlayer = GameObject.FindGameObjectWithTag("SoundController"); Music music = audioPlayer.GetComponent <Music>(); music.changeMusic(SceneManager.GetActiveScene()); } FindObjectOfType <CameraMotor>().isFollowing = true; } // Updates score and other variables if the game is running if (isGameStarted) { score += (Time.deltaTime * modifier); scoreText.text = score.ToString("0"); timeSinceGarbageCollected += Time.deltaTime; if (timeSinceGarbageCollected > 3.5f) { garbageCollected = false; timeSinceGarbageCollected = 0.0f; } // Ends the game when the user has reached the end. if (!isEndless) { if (score > 100 && !isFinished) { isGameStarted = false; playerMotor.StopRunning(); compMotor.StopRunning(); cameraMotor.StopFollowing(); DialogueAnimator.SetBool("isOpen", true); isFinished = true; isGameOver = true; if (TrashSpawner.garbageMultiplier <= 0.5f) { endCutscene.Begin(); } else { lostGame = true; lossCutscene.Begin(); } if (Settings.isMusicOn.Value) { StartCoroutine(AudioController.FadeOut(musicPlayer, 0.5f)); } } } } } if (lostGame && !DialogueAnimator.GetBool("isOpen") && !openedDeathMenu) { openedDeathMenu = true; OnDeath(); } if (!lostGame && !DialogueAnimator.GetBool("isOpen") && isFinished) { isGameOver = true; SceneManager.LoadScene("Forest"); } }