Button's script don't work?

I have a problem. For my game I want to make a pause menu with two buttons, home and resume. The resume button, I think you know what it does, but the problem is with the home button. In the code area the name of the scene to which the home button should lead(StartMenu), appears in red. Obviously if I click on “home”, it does nothing. What can I do? I checked if the name of the scene is spelled correctly, it is, I checked if the scene is active, it is. The code I am using is:


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PauseMenu : MonoBehaviour
{
    public static bool IsGamePaused = false;

    [SerializeField] GameObject pausepanel;

    private void Update()
    {
        // ESCAPE PAUSE BUTTON
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (IsGamePaused)
            {
                Resume();
            }
            else
            {
                Pause();
            }
        }
    }


    //RESUME BUTTON
    public void Resume()
    {
        pausepanel.SetActive(false);
        Time.timeScale = 1;
        IsGamePaused = false;
    }


    //PAUSE BUTTON
    public void Pause()
    {
        pausepanel.SetActive(true);
        Time.timeScale = 0;

        IsGamePaused = true;

    }
    

    // HOME BUTTON
    public void LoadMenu()
    {
        Time.timeScale = 1;
        IsGamePaused = false;

        SceneManager.LoadScene("StartMenu");
    }
} 
1 Like

FYI: This is a UI question, not a 2D feature question so I’ve removed the 2D tag.

Thanks.

1 Like

Oh, thanks for letting me know. I’m a beginner in unity and I didn’t know

1 Like

Read the docs that says next:
When timeScale is set to zero your application acts as if paused if all your functions are frame rate independentUnity - Scripting API: Time.timeScale

So, Input.GetKeyDown() is dependent on frame rate.

For example, In my FPS Shooter I made pausing that independent of Time.timeScale.

What do you mean here? I can’t really parse this sentence.

What’s “the code area”? The console window? Or are you getting errors in your code editor?
Nothing in Unity just appears in red. You get error messages that are red, but those have some text explaining the error.

Usually when somebody new can’t load a scene, it’s because the scene has not been added to the build settings. In that case, your error message should be along the lines of “can’t load the scene StartMenu because it has not been added to the build settings”. In that case, you need to open File->Build Settings and add the scene to the list.

I mean in Visual Studio, StartMenu appears in red and the home button does not take me to scene 0, the StartMenu. It is selected in Build settings