I have this code:
protected const int MAX = 2;
public static List<int> scenes;
void Start()
{
scenes = new List<int>(Enumerable.Range(1,MAX)); // This creates a list with values from 1 to 2
OnLevelWasLoaded(0);
DontDestroyOnLoad(gameObject);
}
private void OnLoadNextLevelHandler()
{
int randomIndex = Random.Range(0, scenes.Count);
int level = scenes[randomIndex];
scenes.RemoveAt(randomIndex); // Removes the level from the list
Application.LoadLevel(level);
}
What happens is that it loads the first level fine, it tells me that the list contains 2 levels (which is correct) but by the time the second scene is loading it tells me that my scene list is 0 so the game is ending before the next scene loads correctly. Can anyone tell me why my code is getting rid of my second scene before it loads correctly?