- Home /
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
- Buttons won't work no matter what I do
Camera won't lock in place when paused
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);
}
}
Answer by blueshark- · Feb 06, 2019 at 09:52 AM
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.
Make sure your script is attached like that to the button.
Ok after looking back I changed nothing but it works now. I guess Unity just needed to be reset. Thanks for answering.
Your answer
Follow this Question
Related Questions
Add force when button is pressed 2 Answers
iTween issue creating a gui. menu box 1 Answer
Where is my OnClick in the button script? 1 Answer
GUI Buttons not working after scene transition 0 Answers
Unity multiple button on click 1 Answer