Search code examples
c#monodevelopunity-game-engine

Scene Management in unity2D


I'm working on unity 2d , and in one part i have to load the next scene(for example c) , if the user presses space .
I have this part of code and I have attached it to the main scene , but it doesn't do anything .

void Update () {

if (Input.GetKey (KeyCode.Space))   {
                        SceneManager.LoadScene('c');
    }

}


Solution

  • Did you add the scene you are trying to load to the Build Settings? Scenes have to be added to the 'Scenes In Build' to be newly loaded. You can access Build Settings through File > Build Settings.

    SceneManager.LoadScene: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html