I need help with pause menu

I made a 1st person camera and a pause menu but when testing when I pause my mouse is gone because its 1st person game therefore I cant click and when I put

if (PauseMenu.GameIsPaused = true) {
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
        }

in the camera script, it just spams the GameIsPaused = true in the console and when I try to open the pause menu it freezes my game like its supposed to but the UI doesn’t show up but when I remove it and test it it spams GameIsPaused = false and I can open the pause menu like normal but can;t see the mouse

Script:

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

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

    public GameObject pauseMenuUI;
   
    //Update is called once per frame
    void Update() {
        Debug.Log(GameIsPaused);

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if  (GameIsPaused)
            {
                Resume();
            }  else
            {
                Pause();
            }
        }
    }

    public void Resume ()
    {
        pauseMenuUI.SetActive(false);
        Time.timeScale = 0f;
        GameIsPaused = false;
    }

    public void Pause ()
    {
        pauseMenuUI.SetActive(true);
        Time.timeScale = 0f;
        GameIsPaused = true;
    }



}

You wrote = (single-equals, the assignment operator) where you meant == (double-equals, the equality test)

OHHHHHH

The other thing I dont get is that when I try to click the buttons in the pause menu my mouse just disappears and I cant get the mouse back unless I close the pause menu (sec) and then reopen it

You set timeScale to 0 both in resume and pause, i think you mean resume to set it to 1(or the timescale used before pause was called)

I just fixed that but when I pause the game while testing and try to press the button(Resume,Menu,Quit) my mouse just disappears and I cant get it back unless I unpause it then repause it

That sounds like a totally separate problem that would require a completely new set of information to solve.

1 Like

why not set cursor state in the pause and resume functions?

where is this and where else do you set cursor state?

if (PauseMenu.GameIsPaused = true) {
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
        }

I put it in my script for my camera

Script:

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

public class MouseLook : MonoBehaviour
{
    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;

    // Start is called before the first frame update
    void Start()
    {

        Cursor.lockState = CursorLockMode.Locked;
        if (PauseMenu.GameIsPaused == true) {
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
        }
    }

    // Update is called once per frame
    void Update()
    {
       


        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);


        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }

you only do it on start, and you only change it from unpaused to paused.
either change the cursor in the pause and resume functions or move this check to update and take the other case into account.

Well when I did that and I pause and its fine but if I unpause by pressing esc not the resume button I can still see my mouse