Hi @LuckieLuuke ,
SceneManager.sceneLoaded is used for specifying a delegate to be called once the scene has loaded.
SceneManager.LoadScene() is an overloaded method, e.g. you can use more than one variety of the same method.
The version you have used so takes a String as the name of the scene to load. There is a second which takes in an int which represents the build index for the scene from your build settings.
As per the documentation however, it is recommended that you use SceneManager.LoadSceneAsync() instead. This also provides an overloaded method where you can specify the build index of the scene to load instead of the name.
Just as a note of caution; in the Unity course, from memory you have the scenes in this order;
- 01 - Start Main
- 02 - Level_01
- 03 - Level_02
- 04 - Level_03
- 05 - Loose Screen
- 06 - Win Screen
You will want to check that the conditions for starting a new game, losing, and winning all use the method which takes in a String and specify the name of the scene - for example, when a player completes Level_03, if you don’t specify that this is the last playable scene and call Win, you will end up calling LoadSceneAsync()
and pass in the current scene build index + 1 - which will take you to the Loose Screen.
You may also want to consider re-ordering the scenes.
In order to obtain the active scene build index you could use something like;
private int _activeSceneBuildIndex = 0;
and
Scene activeScene = SceneManager.GetActiveScene();
_activeSceneBuildIndex = activeScene.buildIndex;
SceneManager.LoadSceneAsync(++_activeSceneBuildIndex);
You would probably want to store this in your levelManager
and set it from a method call in your Start()
method, perhaps;
void Start()
{
Initialise();
}
private void Initialise()
{
Scene activeScene = SceneManager.GetActiveScene();
_activeSceneBuildIndex = activeScene.buildIndex;
}
Then update the methods where you are actually loading the next scene with;
SceneManager.LoadSceneAsync(++_activeSceneBuildIndex);
Hope this helps.