public void GoToNextLevel() { int nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1; if (SceneManager.sceneCountInBuildSettings > nextSceneIndex) { GoToLevel(nextSceneIndex); } else { // Show game completed menu, if it doesn't exist, go to the main menu LevelUI LevelUI = GameObject.Find("UI Manager").GetComponent <LevelUI>(); GameObject GameCompletedParent = GameObject.Find("GameCompletedParent"); GameObject GameCompletedMenu = GameCompletedParent.transform.GetChild(0).gameObject; if (LevelUI != null && GameCompletedMenu != null) { LevelUI.GetComponent <LevelUI>().isPause = true; GameCompletedMenu.SetActive(true); GameCompletedMenu.GetComponent <Animator>().SetBool("SlideOut", true); } else { GoToLevel(0); } } }