- Home /
Event to change level
I want to implement a loading screen between every level change I make. I have made a simple scene with a background image and a "Loading" text. My idea is to load this scene first and afterwards load the desired level.
The problem is that I don't want to create 10 scenes for each level transition and since I can't do something like Application.LoadLevel("LoadingScene","nextLevelname") I won't be able to know what Scene name to pass inside the LoadingScene.
I want to know how to do this using events. I want to fire up an event passing the Scene i want to load as a parameter. Then , inside my Loading Scene I will call Application.LoadLevel("LevelNamePassedByEvent").
PS: I do not have the PRO version to use LoadLevelAsync.
I believe the easiest & best method would be to store a public static string nextLevelName which you put in a persistent script (DontDestroyOnLoad). Set it, load your loading scene and get it. I'm not sure why you'd want to use an event, but this seems easier
And how should I get it from a different scene ?I assume this variable will only be defined in my main scene?
Check this out. http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
This method allows objects (and their scripts) to not be destroyed when the scene is changed.
Answer by IvovdMarel · Jun 09, 2014 at 06:46 PM
Posting as answer:
Check this out. http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
This method allows objects (and their scripts) to not be destroyed when the scene is changed.