// public void UnloadOldScene() { // Debug.Log("Unloading scene."); // IEnumerator UnloadOldSceneInternal() { // Debug.Log("Unloading scene."); // var menuScene = SceneManager.GetSceneByName("MainMenu"); // // If the main menu has been loaded, unload it. // Debug.Log("For real."); // yield return SceneManager.UnloadSceneAsync(menuScene); // Debug.Log("Done."); // } // StartCoroutine(UnloadOldSceneInternal()); // } IEnumerator DoGame() { SetEnabledForSubsystems(false); _timer.CurrentTime = _gameTime; // Wait a couple seconds. yield return(new WaitForSeconds(2.0f)); // Show some animations at the start. foreach (var anim in _animationsAtStart) { yield return(anim.PlayAndWait()); } // Turn on game. SetEnabledForSubsystems(true); // Start Coroutines. var timerCoroutine = StartCoroutine(_timer.DoTimer()); var starCollision = StartCoroutine(WaitOnStarCollision()); // Wait for the first one to finish. Coroutine firstCoroutine = null; yield return(WaitForFirst(coro => firstCoroutine = coro, timerCoroutine, starCollision)); // Stop the coroutines. StopCoroutine(timerCoroutine); StopCoroutine(starCollision); // Turn off game. SetEnabledForSubsystems(false); // Wait for a second! yield return(new WaitForSeconds(1.5f)); // If it was the star, we lose. If it was the timer, we.. win? if (firstCoroutine == timerCoroutine) { // Check for high score. var highScore = PlayerPrefs.GetInt(HighScoreName, 0); if (CurrentScore > highScore) { PlayerPrefs.SetInt(HighScoreName, CurrentScore); } // Show win screen. _winScreen.SetActive(true); } else if (firstCoroutine == starCollision) { _loseScreen.SetActive(true); } }