- Home /
load all scene at ones randomly
I have lots of scene and what i want to do is load them one after another but each time i press start game it will automatically arrange them randomly. Load all, not 1 at a time.
Answer by DiegoSLTS · Mar 14, 2015 at 03:12 PM
I'm not sure what you mean, but I guess you want to "LoadLevelAdditive" to load scenes without "unloading" another.
For the random loading, add an array called "LevelIds" (or anything you want) in the same script that will call the LoadLevelAdditive. Initialize the array with all the level ids you want to randomly load. The array could be an array of strings with all the names of the scenes or an array of ints, with all the ids of those scenes as they appear in the Build Settings window.
Then, randomize the array doing something like this: http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
And the last step, iterate over the array calling LoadLevelAdditive for every element in the array.
eh, I didnt really get the random list thing... you've got an example of a code maybe?
There's sample code in that link. The code is a while loop that picks one element of the list and swaps it with a random element of that list. The loop runs a number of times equal to the lenght of the list so every element is moved to a random place.