Another variation of the next level method

My version of those methods…i choose to set -1 to the scene count, because it make more sense for me on whats really happening under the hood…Rick version is a bit cleaner but this will help me better remeber how this works next time.

    void SceneLoader()
    {
        idLevel = SceneManager.GetActiveScene().buildIndex;
        SceneManager.LoadScene(idLevel);
    }

    private void NextLevel()
    {
        idLevel = SceneManager.GetActiveScene().buildIndex;
        if (idLevel == SceneManager.sceneCountInBuildSettings - 1)
        {
            idLevel = 0;
        }
        else
        {
            idLevel++;
        }
        SceneManager.LoadScene(idLevel);
        
    }

Privacy & Terms