Search code examples
c#unity-game-engineunityscript

Create one loading scene for many levels in Unity3d


I have a problem with loading scene. I've create a loading scene, and then when the it's finished, it loads another level, that's the concept, right? Now, the problem is that if I have so many scenes to load, do I have to create so many loadings scenes, too? I wonder if there are some ways so that when I load another level I still do it through the first loading scene, so I don't have to create so many loading scenes.

Here's the logic of what I've done right now: if i have 10 scenes to load, I have to create 10 loading scenes too...


Solution

  • You can set a variable in PlayerPref how an int for the level you need to load. Your Loadscene got this value and load this.

    In your currentScene to be unloaded:

    PlayerPrefs.SetInt ("NextLevel",x);
    

    In your LoadSceneLevel:

    int nextlevel = PlayerPrefs.GetInt ("NextLevel");
    Application.LoadLevel(nextlevel);