- Home /
How to check if loading from another level or game start?
How do I determine if the first Unity scene is loaded because the application is just being opened, or because it was loaded from another scene?
Details:
I have a unity scene acting as my main menu and level selection screen. When the player runs the game initially (loading the webpage/launches app) I always want this main menu scene to open at the start screen.
However when this main menu scene is loaded from quitting one of the game's levels, I want to load into the level select section instead.
Is there some variable that lets me check what called the level load? Thanks
Answer by syclamoth · Nov 17, 2011 at 10:23 PM
Just keep an object saved with 'DontDestroyOnLoad' that holds all of this information.
And within that script, use OnLevelWasLoaded(int level) to run your code that loads the level select section when level = whatever your main menu scene is.
I just spawned an empty game object prefab that has a unique Tag. Then check if that object exists on awake. If it doesn't then the main menu starts at the title screen and I spawn that prefab. If it does exist I jump to the level select screen.
Thanks for the help.