So my idea is to create a scene changer that randomizes which scene will be played whenever a level is completed. However I want to make sure that the next scene being randomized is not the current scene.
Here is what I did in my “wait” method (sceneName is a variable containing the name of the current scene):
Enumerator Wait()
{
if (sceneName == "A")
{
yield return new WaitForSeconds(2.0f);
SceneManager.LoadScene("Game", LoadSceneMode.Single);
}
else if(sceneName == "Ran1"){
yield return new WaitForSeconds(2.0f);
string[] zones = new string[2] {"Ran2", "Ran3" };
int random = Random.Range(0, 2);
Application.LoadLevel(zones[random]);
}
else if (sceneName == "Ran2")
{
yield return new WaitForSeconds(2.0f);
string[] zones = new string[2] { "Ran1", "Ran3" };
int random = Random.Range(0, 2);
Application.LoadLevel(zones[random]);
}
else if (sceneName == "Ran3")
{
yield return new WaitForSeconds(2.0f);
string[] zones = new string[2] { "Ran1", "Ran2" };
int random = Random.Range(0, 2);
Application.LoadLevel(zones[random]);
}
else
{
yield return new WaitForSeconds(2.0f);
string[] zones = new string[3] { "Ran1", "Ran2", "Ran3" };
int random = Random.Range(0, 3);
Application.LoadLevel(zones[random]);
}
}
It technically works, but it doesn’t seem to be very dynamic.
How can I revise this to not use a bunch of if statements?