//This function handles the game over event IEnumerator GameOver(float delay) { //Go through all the powerups and nullify their timers, making them end for (index = 0; index < powerups.Length; index++) { //Set the duration of the powerup to 0 powerups[index].duration = 0; } yield return(new WaitForSeconds(delay)); //If there is a source and a sound, play it from the source if (soundSource && soundGameOver) { soundSource.GetComponent <AudioSource>().PlayOneShot(soundGameOver); } isGameOver = true; //Hide the pause screen and the game screen if (pauseCanvas) { pauseCanvas.gameObject.SetActive(false); } if (gameCanvas) { gameCanvas.gameObject.SetActive(false); } //Show the game over screen if (gameOverCanvas) { //Show the game over screen gameOverCanvas.gameObject.SetActive(true); //Write the score text gameOverCanvas.Find("TextScore").GetComponent <Text>().text = "SCORE " + score.ToString(); //Check if we got a high score if (score > highScore) { highScore = score; PersistenceController.CheckHighscore(highScore); } //Write the high sscore text gameOverCanvas.Find("TextHighScore").GetComponent <Text>().text = "HIGH SCORE " + highScore.ToString(); // Show bonus button bonusCanvas.gameObject.SetActive(Advertisement.IsReady()); } //Check if the longest streak is greater than the persisted one, if it is, persist it int persistedLongestStreak = PersistenceController.playerData.playerStats.longestStreak; if (longestStreak > persistedLongestStreak) { Debug.Log($"New Longest Streak Persisted ! (old: {persistedLongestStreak}, new: {longestStreak})"); PersistenceController.playerData.playerStats.longestStreak = longestStreak; PersistenceController.SavePlayerData(); } }