x


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!

more ▼

asked Jun 13 '12 at 03:05 PM

Fattie gravatar image

Fattie
19k 57 86 148

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jun 13 '12 at 03:09 PM

Wolfram gravatar image

Wolfram
9k 8 20 52

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x104
x66
x43

asked: Jun 13 '12 at 03:05 PM

Seen: 905 times

Last Updated: Jun 13 '12 at 03:09 PM