You can disable the MouseLook ability by setting the .enabled flag to false, and then again to true on unPause. I was able to test and get it to work with this:
I added the following to the if(!paused) and set them true again in the else if(paused).
PlayerMouseControllerX.enabled = false;
PlayerMouseControllerY.enabled = false;
using UnityEngine;
using System.Collections;
public class PauseMenu2 : MonoBehaviour
{
public bool Paused = false;
public bool ShowPauseMenu = false;
public bool ShowOptionsMenu = false;
public static float SensitivityX = 1f;
public static float SensitivityY = 1f;
public MouseLook PlayerMouseControllerX;
public MouseLook PlayerMouseControllerY;
// Use this for initialization
void Start()
{
Paused = false;
Time.timeScale = 1;
Screen.lockCursor = true;
Screen.showCursor = false;
ShowPauseMenu = false;
PlayerMouseControllerX.sensitivityX = SensitivityX;
PlayerMouseControllerY.sensitivityY = SensitivityY;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (!Paused)
{
Paused = true;
Time.timeScale = 0;
Screen.lockCursor = false;
Screen.showCursor = true;
ShowPauseMenu = true;
PlayerMouseControllerX.sensitivityX = 0;
PlayerMouseControllerY.sensitivityY = 0;
PlayerMouseControllerX.enabled = false;
PlayerMouseControllerY.enabled = false;
}
else if (Paused)
{
Paused = false;
Time.timeScale = 1;
Screen.lockCursor = true;
Screen.showCursor = false;
ShowPauseMenu = false;
PlayerMouseControllerX.sensitivityX = SensitivityX;
PlayerMouseControllerY.sensitivityY = SensitivityY;
PlayerMouseControllerX.enabled = true;
PlayerMouseControllerY.enabled = true;
}
}
}
void OnGUI()
{
{
if (ShowPauseMenu)
{
// Make a background box
GUI.Box(new Rect(10, 10, 650, 300), "Paused");
// Make the resume button
if (GUI.Button(new Rect(290, 100, 80, 20), "Resume"))
{
ShowPauseMenu = false;
Time.timeScale = 1;
Screen.showCursor = false;
Screen.lockCursor = true;
}
// Make the second button that will kill the process
if (GUI.Button(new Rect(290, 200, 80, 20), "Quit"))
{
Application.Quit();
}
if (GUI.Button(new Rect(290, 150, 80, 20), "Options"))
{
ShowPauseMenu = false;
ShowOptionsMenu = true;
}
}
else if (ShowOptionsMenu)
{
GUI.Box(new Rect(10, 10, 650, 300), "Options");
GUI.Label(new Rect(150, 200, 150, 20), "Sensitivty X: (" + SensitivityX.ToString() + ")");
GUI.Label(new Rect(150, 225, 150, 20), "Sensitivty Y: (" + SensitivityY.ToString() + ")");
SensitivityX = GUI.HorizontalSlider(new Rect(200, 200, 150, 20), SensitivityX, 0.1f, 20f);
SensitivityY = GUI.HorizontalSlider(new Rect(200, 225, 150, 20), SensitivityY, 0.1f, 20f);
//If the "Return" button is pressed, go back to the main menu
if (GUI.Button(new Rect(209, 100, 80, 20), "Return"))
{
ShowPauseMenu = true;
ShowOptionsMenu = false;
}
}
}
}
}