Lock FPS Controller mouse in menu

Hello everyone!

Here is my problem, sorry if this has been already answered, but I can’t find anything that works for me (or that I can understand, super newbie here)

I’m using the standard FPS Controller prefab in my scene, I did a menu that open when I press escape, with two buttons, restart and quit. But I can not interact with them. When I press escape, the menu appears, but the buttons doesn’t work, highlighted neither, and the Player can still move. When I press escape the cursor appears, but disappear as soon as I click anywhere. Same behaviour if I uncheck “Lock Cursor” in FPS Controller inspector except the cursor is always visible.

Is there any way to fix this? Do I need to change anything in FPS Controller script? Or in MouseLook script?
Again i’m very very new so please talk to me like I’m a five years old…

Here is my menu script so far… Maybe something wrong in it also…

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

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

    public GameObject pauseMenuUI;

    // Update is called once per frame
    void Update()
    {
     if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (GameIsPaused)
            {
                Resume();
            }
            else
            {
                Pause();
            }
        }  
    }

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

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

    public void RestartGame()
    {
        Time.timeScale = 1f;
        SceneManager.LoadScene(SceneManager.GetActiveScene().name); // loads current scene
        Debug.Log("Restarting game...");
    }

    public void QuitGame()
    {
        Debug.Log("Quiting game...");
        Application.Quit();
    }
}

Thanks a lot for your time and help.

1 Like

Since you have your menu script separate from your FPS script I recommend using get component on the FPS controller and disabling the script component while the menu is enabled. You can then do an if check and re-enable it all from the menu script you have here when you press the key again.

This should prevent any interference from the FPS controller and let you keep your cursor on as normal.

1 Like

Ok thanks that sound great! But I’m really sorry, could you if you have any time translate this into script, and point where, how I should put things.
Again sorry I’m really really new…

GetComponent<FPSController>().isenabled = false

This is just pseudo code but you should be able to work it out from there.

1 Like

Thanks but I can’t get my menu Script to find the FirstPersonController Script.
What am I doing wrong here? :
Both are on the same folder in my assets

You’ve made your script private so that means you won’t be able to access it, also the part at the top is unnecessary if you’re using GetComponent in a function. If your FPSControllerScript is in the hierarchy somewhere else or named differently you’ll need to do GetComponentInChildren or GetComponentInParent.

Edit: Extra note, when you’re directly referencing the script with GetComponent you should pick the actual script name, you haven’t entered it in correctly in your GetComponent code. When you type in the script name autocomplete should come up and you should be able to select the existing script.