Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Randomly loading either of two scenes.

Discussion in 'Scripting' started by cristo, Jan 1, 2019.

  1. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Hi, I would like to load either of two scenes. 1 or 3. Like a random bool. Not a range between 1 and 3. Any advice would be great. Thankyou for your time.

    Code (CSharp):
    1. public class SceneChangeRandom  : MonoBehaviour
    2. {
    3.  
    4.  
    5.     public void ChangeToSceneRandom(int rRandom) {
    6.  
    7.  
    8.         int [] scene = new int[] { 1, 3 };
    9.         var rrRandom = new Random (scene);
    10.  
    11.  
    12.         Application.LoadLevel(rRandom);
    13.  
    14.  
    15.    
    16.     }
    17. }
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Code (CSharp):
    1. if(Random.value < 0.5f){
    2. //do thing 1
    3. }else{
    4. //do thing 2
    5. }
     
    cristo likes this.
  3. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Thanks!