How can I make my main menu load up when the player hits the door?

I’m trying to make it so when my player gets five points and they collide with the door, the menu screen for my game shows up. I thought this code was fine but the main menu won’t show when I collide with the door. Can anyone help me fix this? Here is my code below:

    private void OnTriggerEnter(Collider door)
    {
        if(door.tag == "Door" && points == 5)
        {
            SceneManager.LoadScene("MainMenu");
        }
    }
}

Im also using unityengine.scenemanagement too. The rest of the code including the points works fine it’s just the loading of the scene that won’t work.

Try checking your scene setup, I can’t immediately spot anything wrong with this code so it’s probably that you’ve forgotten to set a tag somewhere or make your collider a trigger. Don’t forget as well if you build your scene to add the scenes being loaded. You’re using strings as well so remember they’re case sensitive.

1 Like

This.

private void OnTriggerEnter(Collider door)
{
    if(door.tag == "Door" && points == 5)
    {
        Debug.Log("loading main menu");
        SceneManager.LoadScene("MainMenu");
    }
}

Just debug log to see where to look. If the message doesn’t appear it’s potentially a tag or collider issue, if it does appear then most likely you haven’t added the scene to the build index list.

it turns out it was a naming error. got names mixed up its all sorted now thanks guys

1 Like