Is it ok to use SceneCountInBuildSettings for the Core Game Scene?

I assume that we are going to change the script on the core game scene’s button? If it just goes to the next scene, when we add more - I thought that would cause problems. I didn’t understand the challenge so I was scratching my head for a while and made this, which also seems to work:

    public void LoadFinalScene()
    {
        int sceneCount = SceneManager.sceneCountInBuildSettings;
        SceneManager.LoadScene(sceneCount - 1);
    }

I didn’t know if that was correct, and I assumed that’s why maybe you had us look at the build settings. But when I continued watching the video I saw you guys just said to go to next scene. ^^’

Hi Ash,

In most cases you’d probably want a LoadNextLevel type of method, as an example, if you have 20 playable levels, you can just keep moving through them quite easily - however - as you have already identified in your code, you need to consider what happens if its the final level.

Sometimes you’ll see the Game Won scene added to the build settings as the last level, that way you can keep using LoadNextLevel all the way through and you’ll just get to the end smoothly, you could also perform a check before using LoadNextLevel to determine if the current level is the last playable level and then load whatever scene you want.

Regarding your question about using SceneManager, one of the benefits of having all of the level loading methods, e.g those that are using SceneManager encapsulated into another class is that should anything ever change with Unity’s API, you can tackle it easily in the one place, rather than having to search across your application for every reference of SceneManager. This was actually an issue around Unity 5.x, the original methods were named LoadLevel and were renamed to LoadScene, having them all in the one class makes it easy to update, it also keeps the responsibility for loading levels in that class.

Hope this helps :slight_smile:

Privacy & Terms