Scene Loading Challenge

Here was what I came up with. I’m sure it could be simplified, but I’m not sure how much should be done at the same time.

private void LoadNextLevel()
{
    int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    int totalSceneCount = SceneManager.sceneCountInBuildSettings;
    int nextSceneIndex;
    if (currentSceneIndex < totalSceneCount - 1 )
    {
        nextSceneIndex = currentSceneIndex + 1;
    }
    else
    {
        nextSceneIndex = 0;
    }
    SceneManager.LoadScene(nextSceneIndex);
}

Privacy & Terms