IEnumerator NextLevel() { GameObject raceobj = GameObject.Find("RaceController(Clone)"); if (raceobj) { RaceController race = raceobj.GetComponent <RaceController>(); StartCoroutine(race.FadeOutMusic()); } yield return(_instance.mainCam.FadeOut()); if (showcaseBuild) { Debug.Log("showcase time baby"); int currLevel = SceneManager.GetActiveScene().buildIndex; if (currLevel == 6) { StartCoroutine(LoadSceneAsync(nextLevelCycle)); // if we're on the victory level, load the next scene in the cycle } else { if (currLevel == 5) { nextLevelCycle = 3; // if we're on the brick level, set nextLevelCycle to 3 to go back to dirt land } else { nextLevelCycle = currLevel + 1; } Debug.Log("loading:" + nextLevelCycle); if (currLevel < 3) { StartCoroutine(LoadSceneAsync(nextLevelCycle)); // if we're not at the dirt level yet } // (tutorial/main menu) just load the next scene in the sequence else { StartCoroutine(LoadSceneAsync(6)); // else,jump to the victory stage } } } else { int next = SceneManager.GetActiveScene().buildIndex + 1; next = next % SceneManager.sceneCountInBuildSettings; StartCoroutine(LoadSceneAsync(next)); } }