Hi, I am developing a game which consists of loading a scene as a mission, when it finishes pressing a button (UI) that loads another random scene but that is not the previous one. I am using this script but I have no results, maybe because I am loading another scene and the script is restarted.
Thanks for your help. This my code but dont work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Linq;
public class Manager : MonoBehaviour {
public Button correcto1;
//public int scoreValue = 1;
protected const int MAX = 80;
private List<int> scenes = new List<int>();
void Start () {
scenes = new List<int>(Enumerable.Range(1,MAX));
correcto1.onClick.AddListener (inicfunc);
}
void Update () {
}
void inicfunc()
{
for(int i = 1; i < 80; ++i)
{
scenes.Add(i);
}
// Get a random index from the list of remaining level
int randomIndex = Random.Range(0, scenes.Count);
int level = scenes[randomIndex];
scenes.RemoveAt(randomIndex); // Removes the level from the list
SceneManager.LoadScene(level);
//ScoreManager.score += scoreValue;
//SceneManager.LoadScene (Random.Range (1,5));
//SceneManager.LoadScene("ost2");
}
}