- Home /
How to make a scene load more random than others?
Here is a working code where a random scene is loaded via trigger etc between 2 and 5. However I want scene 4 to less likely appear than the others, I hope this is not too complicated, thanks in advance. I was thinking of (Random.Range(2,2,2,4,5,5,5,6,6,6)) something like that but I got errors.
Application.LoadLevel(Random.Range(2, 6));
Answer by Landern · Nov 26, 2014 at 02:55 PM
Put your sequence in an array, use random.range to select value out of the array:
int[] levelNumbers = int[10] { 2,2,2,4,5,5,5,6,6,6 };
Application.LoadLevel(levelNumber[Random.Range(0, 9)]); // arrays are base 0.
I forgot to mention, i'm very new to unity and program$$anonymous$$g. I've never used arrays, do I put this code at the top of the script? int[] levelNumbers = int[10] { 2,2,2,4,5,5,5,6,6,6 };
Yes, if you're using java/unityscript, if you place it out of a function, it will be available to the inner functions.
Your answer
Follow this Question
Related Questions
Number of scenes for iPhone games 1 Answer
Switching scenes 1 Answer
On carachterspawn level load error? 0 Answers
How to take a GameObject from A scene to B scene when the GO was instantiated? 1 Answer
connect to hosted level 0 Answers