how to load random / shuffle scene without repeating current scene? (when button next level pressed)
hi, im newbie. please help me to solve these problem. (im using unity 2018.4.28f1)
so, i make an android platformer game. i have several scene. the first scene (main menu) has a game button, and when it pressed it will appear a randomized level.
and then, when the player successfully passes the level, there is a screen with "next level" button (the button could randomize next scene)
but, when it pressed. it could be random scene, and could be repeating scene. what i want is, when the scene has been played, the scene can't be repeated again and a random new scene appears until all scene finish. please tell me the full tutorial because im very newbie. thanks in advance! it helps me a lot
so here is my code in a gameobject called RandomScene, the gameobject is part of inspector Button "Next Level" & MainMenu (in inspector: OnClick () -> LoadRandomScene.RandomScene
)
using System.Collections; using System.Collections.Generic; using
UnityEngine; using
UnityEngine.SceneManagement;
public class LoadRandomScene :
MonoBehaviour {
// Start is called before the first frame update
public void RandomScene()
{
int index = Random.Range(5,9);
SceneManager.LoadScene(index);
Debug.Log("Scene Loaded");
}
}
Your answer
Follow this Question
Related Questions
Random.Range code problem or problem with Unity? 1 Answer
Random platform Generator 1 Answer
Random Scenes Without Repetition 1 Answer
List or Arrays, and how to randomize them. 1 Answer
Randoming in a Randomed variable 1 Answer