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
  4. Dismiss Notice

Question How to change the Scene to random.

Discussion in 'Scripting' started by lsk111919, Sep 7, 2020.

  1. lsk111919

    lsk111919

    Joined:
    Jul 8, 2020
    Posts:
    19
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.SceneManagement;
    7.  
    8. public class Quiz : MonoBehaviour{
    9.     public Text text = null;
    10.     public List<string> SceneList = new List<string>() { "41", "42", "43", "44", "45" };
    11.  
    12.     private void Update()
    13.     {
    14.      
    15.     }
    16.     public void LoadRandomScene()
    17.     {
    18.         for (int i = 1; i < 6; i++)
    19.         {
    20.             int rand = Random.Range(0, SceneList.Count);
    21.             SceneManager.LoadScene(SceneList[rand]);
    22.             SceneList.RemoveAt(rand);
    23.         }
    24.     }
    25. }
    I've created a code that changes Scene randomly, but I'd like to have the next screen printed after a few seconds on the first screen. What should I do?
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    Please try to refrain your Question since "I'd like to have the next screen printed after a few seconds on the first screen."
    is not understandable :eek: ,

    next screen? Do you mean your "Next Screen" UI ? Or Scene?
    first screen? UI, Scene?
     
    Javilingys and eses like this.
  3. Javilingys

    Javilingys

    Joined:
    Nov 23, 2017
    Posts:
    7
    What do you want? You want choose screen number 2 for example, write before load new scene that scene number 2 will load and after that load scene number two?
     
  4. Javilingys

    Javilingys

    Joined:
    Nov 23, 2017
    Posts:
    7
    If you want a delay, look at Coroutine ))
    Or if very very simple, than Invoke(); function)
     
  5. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,469
    Store your scene reference in an objects, that objects has a field with the name of the scene, select the object randomly instead of the scene, when the object is selected, call the scene it reference and use the name it reference.