Scene won't load on button click

Hi all.

I have currently two scenes in my game. When the player dies in scene-1 it loads the 2nd scene, which has a button to click to go back to scene-1. I’ve added all the scenes to Build Settings, assigned the loading function to the button – but the button won’t load the scene-1. However, when I use Enter key to load scene-1, it works fine. I can’t figure out why the button won’t work.

Code for the Button (Not working):

public void LoadScene(int sceneN)
    {
        SceneManager.LoadScene(sceneN);
    }

Code for the “Enter” key (Works):

private void Update()
    {
        if(Input.GetKeyDown(KeyCode.Return))
        {
            SceneManager.LoadScene(0);
        }
    }

Click event for the button:
7242953--872312--Image 025.jpg

Build Settings:

Here’s what it looks like when playing:

Thanks for any help!

Are you missing an EventSystem in your UI scene? I don’t see one in your hierarchy and your default button doesn’t look like it’s animating.

1 Like

Yes, thanks, I created a new UI scene and now it works. I’m exactly not sure what went wrong earlier though…

You may have accidentally deleted the EventSystem in the second scene. It’s needed to track interactive UI elements. Keyboard events are handled by the Input class and don’t need the EventSystem.
Game looks cool :slight_smile:

3 Likes

Thanks mate :slight_smile:

1 Like