How can I make random scene loader?

Hi all
I’ve looked around the web and found some old code but since Unity has changed, I wanted to find out the best way to generate random scenes within Unity 5.

It’s a platform game and I wanted to make 20-30 small scenes that could be picked at random as the player progresses.

Any suggestions on the best practice and code for making this happen please?

thanks
G

Lets say you have 30 scenes. Call them something like scene1, scene2, scene3 all the way up to scene30 and just call a simple method:

int randomScene = Random.Range(1, 30); //gives you a random number from 1 to 30
Application.LoadLevel(“scene” + randomScene.toString()); or SceneManager.LoadScene(“scene” + randomScene.toString());

1 Like

Many thanks! I will give this a whirl.

Or just do:

Application.LoadLevel(Random.Range(0, 30));

This works regardless of the scene names.

1 Like

Now it should be

SeneManager.LoadScene(Random.Range(0, 03));
1 Like