Question on LoadNextScene()

Instead of creating a new method to load the start scene, I added another variable nextSceneIndex that gets a value of currentSceneIndex +1, and then I check to see if nextSceneIndex is greater than or equal to SceneManager.sceneCountInBuildSettings. If it is, then I set nextSceneIndex to 0.

Mine works, but I can see how it’s not completely clear what’s going on. Do you have any opinion on which is better? I can see problems coming for both methods when we add other scenes and other buttons to go from one to another in a non-circular fashion.

Thanks for any insight you can provide.

  • Rob

I was playing with the same idea, you can make your logic a bit more succinct by using a mod operator. Something like this:

SceneManager.LoadScene((currentSceneIndex +1) % SceneManager.sceneCountInBuildSettings)

I suppose the advantage of a seperate method to load start scene is that it makes the intention explicit.

Yeah, I can see that too. Nice use of the % (mod) operator!

I ended up reverting mine to the example. It’s straightforward, which is helpful as things start to get larger and larger.

Cheers!

Privacy & Terms