Search Unity

Getting all the names of the scene levels AND publishing it???

Discussion in 'Scripting' started by EnsurdFrndship, Oct 20, 2014.

  1. EnsurdFrndship

    EnsurdFrndship

    Joined:
    Apr 17, 2010
    Posts:
    786
    Hello,
    I researched a way on how to get all the names of all the scene levels, but when I publish my game, I get compiler errors. Here is my code in javascript...

    Code (JavaScript):
    1.   var names : List.<String> = new List.<String>();
    2.   names.Clear();
    3.   for (var S  : UnityEditor.EditorBuildSettingsScene in UnityEditor.EditorBuildSettings.scenes) {
    4.     if (S.enabled) {
    5.       var name : String = S.path.Substring(S.path.LastIndexOf('/')+1);
    6.       name = name.Substring(0,name.Length-6);
    7.       names.Add(name);
    8.     }
    9.   }
    10.  
    The variable, 'names' will contain all the names of the levels I put in my build settings of my project. The game runs fine, but the problem happens when I try and publish my game. I get errors like...

    The name 'UnityEditor.EditorBuildSettingsScene' does not denote a valid type ('not found'). Did you mean 'System.ComponentModel.EditorBrowsableAttribute'?
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    You can't use any of the UnityEditor stuff when the game is built. That namespace is only available in Unity's editor.

    I'm not sure how to get the level names at run time. Hopefully someone else knows some Unity magic to make it so.