Pause menu not working

Ok, I had a crappy pause menu script that worked but was terrible, after the last couple Unity updates that pause menu broke and the buttions don’t work anymore. So I decided it was as good a time as any to make a new one.

Problem is nothing I do works, the main menu button won’t load the main menu. The buttons are linked correctly they just don’t work. I click on them and nothing happens. In the current script i’m using it has a Resume game function which I don’t really care for and would rather have a quit game button like my old menu.

Other issues with the pause menu is it won’t lock the camera in place and when I close the pause menu by hitting escape the cursor lingers and you need to click to re-hid and lock it.

So to sum up the problems i’m having are

  1. Buttons won’t work no matter what I do
  2. Camera won’t lock in place when paused
  3. cursor won’t hide and lock after closing pause menu until you click

My understanding of scripting in basic so I can tinker with scripts but have a hard time writing them. Any help to fix this script or recommend a better one would be greatly appreciated. Again I also want to replace the Resume function with a quit game function because their is no point having a resume button when escape is just the resume button.

Here is the script i’m currently using

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

public class MenuController : MonoBehaviour
{
    public string mainMenuScene;   
    public GameObject pauseMenu;
    public bool isPaused;

    //Use this for initialization
    private void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (isPaused)
            {
                Resume();
            }
            else
            {
                isPaused = (true);
                pauseMenu.SetActive(true);
                Time.timeScale = 0f;
            }
        }
    }

    public void Resume()
    {
        isPaused = false;
        pauseMenu.SetActive(false);
        Time.timeScale = 1f;
    }

    public void ReturnToMain()
    {
        Time.timeScale = 1f;
        SceneManager.LoadScene(mainMenuScene);
    }
}

Set update mode of the pauseMenu to “Unscaled Time” this will make it appear even though time is stopped. Make sure every button has the script attached to it with the right function. You could Debug.Log also if they run or not, but your script looks fine.
132608-pausemenu.png

Make sure your script is attached like that to the button.