CTIN 289 - Interactive Snippets Library

Powered by 🌱Roam Garden

Load Next Scene


Simple script for easily loading the next level in the build index. Even has a built in safety protocol for debugging.


    public void LoadNextScene()
    {
        int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
        int nextSceneIndex = currentSceneIndex + 1;

        if (nextSceneIndex < SceneManager.sceneCountInBuildSettings)
        {
            SceneManager.LoadScene(nextSceneIndex);
        }
        else
        {
            Debug.LogWarning("Trying to load a scene that doesn't exist in the build settings.");
        }
    }