I’m not sure what I am missing. But suddenly I started getting ‘out of range’ exception for the scene index
var availableCount = SceneManager.sceneCountInBuildSettings;
var nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
Debug.Log($"LoadNextLevel#1, cur = {SceneManager.GetActiveScene().buildIndex}, next = {nextSceneIndex}, max = {availableCount}");
if (nextSceneIndex >= availableCount) {
// back to the beginning
nextSceneIndex = 0;
}
var scene = SceneManager.GetSceneAt(nextSceneIndex);
Debug.Log($"GetSceneAt({nextSceneIndex}) = {scene.name}");
SceneManager.LoadScene(nextSceneIndex);
There are 2 scenes in the scenemanager. I tried to remove and re-add the scenes, but I still get the same error.
The reason for adding the GetSceneAt was to see if I could get the scens, since the initial ‘loadscene’ does not load the next scene
var availableCount = SceneManager.sceneCountInBuildSettings;
var nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
if (nextSceneIndex >= availableCount) {
// back to the beginning
nextSceneIndex = 0;
}
Debug.Log($"LoadNextLevel, cur = {SceneManager.GetActiveScene().buildIndex}, next = {nextSceneIndex}, max = {availableCount}");
SceneManager.LoadScene(nextSceneIndex);
Any idea what I’m missing.