- Home /
How can I determine if a Scene exists in a Project?
I'm working on what is intended to be an arcade-style, simple, streaming web game. When the last level is reached, I want to be able to reload the first (with a difficulty modifier, of course) and continue play. Each level is its own scene and I'm having no problems loading the next level until I reach the last one.
I'm unable to find any way to programmatically determine when I'm out of scenes. Since I can't tell when I run out, I can't tell when I need to go back to the first one. The current code I have to load the next level is:
if(Application.CanStreamedLevelBeLoaded(LevelNumber.ToString()))
Application.LoadLevel(LevelNumber.ToString());
Where LevelNumber
is an int
representing the level number to load next. Is there a way to check is a Scene with a given name exists within the Project so I can set LevelNumber
back to 1 when I have no more available levels?
I am aware that I could set another variable representing the maximum number of levels there are but I'd prefer to have the program itself handle it so I can include or exclude levels for various builds (for testing and otherwise) without having to remember to change a game constant.
Answer by Mike 3 · Jul 29, 2010 at 11:27 PM
Application.levelCount will give you how many levels there are. Then you just need to check if the current level is < levelCount
Also - why're you using the string version of the LoadLevel instead of the int one?
Nice, I must have missed levelCount
. It seems like it may be my best bet--which will make my reasoning for the use of LoadLevel(string)
obsolete. It was a hastily made decision to make things a bit more simplified when I have a friend of $$anonymous$$e help with level design once the engine is at about beta.
Answer by ffff1111 · Jan 26, 2013 at 01:48 AM
Curiously, this works also with standalone scenes:
Application.CanStreamedLevelBeLoaded
Excellent, thanks for this. (Now, it would really be nice if there was a method Application.GetLevelName(int index) ...)