Load without repeating

Hey all, basically I already searched on the forum but I need to fix what I found for my needings…my problem is this. I have a game of 10 levels. At the end of each level a button spawn and clickin on it you go into the next level. I want everytime the player click this button the engine randomly choose trough all the levels not repeating the level already played. I found this but I don’t know exactly how to use it…someone can clarify to me?

    using UnityEngine;
    using System.Collections.Generic;
    
    public static class SceneManager
    {
        private const int kNumScenes = 5;
        private static List<int> s_SceneList = null;
    
        public static bool NextScene ()
        {
            if (s_SceneList == null)
            {
                s_SceneList = new List<int> ();
                for (int i = 1; i <= kNumScenes; i++)
                {
                    s_SceneList.Add (i);
                }
                for (int i = 0; i < s_SceneList.Count; i++)
                {
                    int index = Random.Range (0, s_SceneList.Count);
                    s_SceneList.Add (s_SceneList [index]);
                    s_SceneList.RemoveAt (index);
                }
            }
          
            if (s_SceneList.Count < 1)
            {
                return false;
            }
          
            int scene = s_SceneList [0];
            s_SceneList.RemoveAt (0);
            Application.LoadLevel (scene);
          
            return true;
        }
    }

plus considering is a old answer maybe there are new methods now to do what I’m looking for…thank you very much for your patience and your time :slight_smile:

Plus seems I can’t add this script to nothing since I have this error message : “can’t add script beahviour SceneManager. The script class can’t be abstract”. :confused:

What are you trying to add that script too? If you want to add it to a GameObject, it needs to be a MonoBehaviour, and not be static.

As far as choosing a random level goes, why not just have a pointer for the current level and use List(T).Remove? List<T>.Remove(T) Method (System.Collections.Generic) | Microsoft Learn

thx for answering but must be a better way to do this I think