- Home /
 
How to load scenes based on specific percentage?
Hello all, thanks for looking at my question. What I am trying to achieve here is when the player presses "Play" on the main menu, 1 of 7 pre-made scenes is to be loaded. Each scene is different in some way. Six of the scenes are pretty generic but I have one scene that is very detailed and neat looking. I would like to make the chances of getting one of the six generic scenes a 16.5% chance and the one surprise scene should have only a 1% chance. The following code shows what I currently have with Random.Range but the effect gives all the scenes the same chance of spawning which is not what I'm looking for.
 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEditMode]
 public class GUI_RandomLevelLoader : MonoBehaviour
 {
     public bool debugMode = false;
     
     public bool centerButton = false;
     
     public Rect button = new Rect(15, 15, 200, 110);
     public string buttonLabel = "Load Level";
     
     public GUISkin skin = null;
         
     private void OnGUI()
     {
         if (debugMode || Application.isPlaying)
         {
             if (centerButton)
             {
                 button.x = (Screen.width * 0.5f) - (button.width * 0.5f);
             }
             
             GUI.skin = skin;
             GUI.Label(button, buttonLabel);
         
         if (GUI.Button(button, buttonLabel))
             Application.LoadLevel(Random.Range(2,9));
         }
     }
 }
 
               The main menu scene is 0 and the game over scene is 1. Scenes 2 through 8 are my levels. I have the number 9 in the Random.Range to ensure the scene 8 is included in the random selection. Thank you all for your time and any help would be greatly appreciated.
Your answer
 
             Follow this Question
Related Questions
Problems with unlocking levels 1 Answer
Level Selector not working on build 0 Answers
How to make an exit level trigger? 3 Answers
manage objects through a manager script 0 Answers
Load scene transistions 1 Answer