0

Unity Random Scene

Example: I have 5 scenes, The Main Menu and the other 4 are the four levels, what I'm trying to achieve is if I click Start Button at Main Menu Scene, it will select random scene from 4 level scene and if I click next at that scene, it will select scene from levels but it will select between remaining 3, not repeated. And then after all scene is selected, the next button of the last scene that is selected, after I click that button, it will go through the main menu scene. I am new to c# and unity. This is for project purpose only. Please provide some code. TIA

11th Sep 2018, 3:01 PM
Mugiwara
Mugiwara - avatar
4 Respostas
+ 1
GPS this should work but if you dont want to have the same scene twice, you should save the scenes you already had. The most data is reset when a new scene is loaded, so you have to save them in PlayerPrefs or in a dontDestroyOnLoad object. I would recommend you to use PlayerPrefs although they can not save any Arrays or something like that (you can only save bool, int, float and string). Instead of setting up five booleans, it would be easier to save one int and look at it as a couple of bits, where you save if you already had this scene before (every bit stands for one scene).
26th Oct 2018, 6:44 PM
Tim
Tim - avatar
+ 1
Tim yeah thats right. Last night I havn’t think about the reset. Thanks for the note :)
26th Oct 2018, 6:54 PM
Gérôme Schmidt
Gérôme Schmidt - avatar
+ 1
https://code.sololearn.com/cLHmo1j3l1cx/?ref=app This code demonstrates how to use an int as a bit or bool array
26th Oct 2018, 7:24 PM
Tim
Tim - avatar
0
hey. It should work with this code: using System.Collections; using System.Collections.Generic; using UnityEngine; using Unity.SceneManagement; public class randomScene : Monobehaviour{ int index = Random.Range(1, 4); SceneManager.LoadLevel(index); }
25th Oct 2018, 10:21 PM
Gérôme Schmidt
Gérôme Schmidt - avatar