- Home /
Get the NAMES of levels programmatically
When you're on your splash screen, you can in fact get the number of levels available to load.... Application.levelCount
This made me realise that during development you can drop in a handy little "load all your scenes" set of buttons, automatically, in your splash scene, so ...
function OnGUI ()
{
var howManyRealLevels = Application.levelCount - 1;
for ( var i:int=0; i<howManyRealLevels; ++i )
{
if ( GUI.Button( Rect(300, 200 + i*120, 200,100),
"scene: " + (i+1) ) ) // LOOK HERE
Application.LoadLevelAsync( i+1 );
}
}
notice "LOOK HERE" in the code. It would be neat if you could just grab the level NAME.
Can it be done? You'd think it's in there in an undocumented list or some such, the thing has to know the names somehow.
(I realize you could look through your own file structure for scenes but that's not a solution, they may not be in there etc. I just want to know if there's a magic to grab the list of names! Just as you can get the count.)
Cheers!
Answer by Wolfram · Jun 13, 2012 at 03:09 PM
Duplicate question: http://answers.unity3d.com/questions/33263/how-to-get-names-of-all-available-levels.html
The link also contains a workaround to do this with an editor script before deployment.
It works fine until I try to publish my game. Then, I get compiler errors that say...
The name 'UnityEditor.EditorBuildSettingsScene' does not denote a valid type ('not found'). Did you mean 'System.Component$$anonymous$$odel.EditorBrowsableAttribute'?