Search Unity

Load without repeating

Discussion in 'Scripting' started by ThisIsSparta, Mar 1, 2015.

  1. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    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?

    Code (CSharp):
    1.     using UnityEngine;
    2.     using System.Collections.Generic;
    3.    
    4.     public static class SceneManager
    5.     {
    6.         private const int kNumScenes = 5;
    7.         private static List<int> s_SceneList = null;
    8.    
    9.         public static bool NextScene ()
    10.         {
    11.             if (s_SceneList == null)
    12.             {
    13.                 s_SceneList = new List<int> ();
    14.                 for (int i = 1; i <= kNumScenes; i++)
    15.                 {
    16.                     s_SceneList.Add (i);
    17.                 }
    18.                 for (int i = 0; i < s_SceneList.Count; i++)
    19.                 {
    20.                     int index = Random.Range (0, s_SceneList.Count);
    21.                     s_SceneList.Add (s_SceneList [index]);
    22.                     s_SceneList.RemoveAt (index);
    23.                 }
    24.             }
    25.          
    26.             if (s_SceneList.Count < 1)
    27.             {
    28.                 return false;
    29.             }
    30.          
    31.             int scene = s_SceneList [0];
    32.             s_SceneList.RemoveAt (0);
    33.             Application.LoadLevel (scene);
    34.          
    35.             return true;
    36.         }
    37.     }
    38.  
    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 :)
     
  2. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    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". :/
     
  3. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
  4. ThisIsSparta

    ThisIsSparta

    Joined:
    May 4, 2014
    Posts:
    142
    thx for answering but must be a better way to do this I think