Pause Menu

Hi, my pause menu isn’t working at all, I’ve followed someone’s code to try and get it working and it just won’t work at all, I hit pause and the menu pops up but I can still look about and move the camera around, what is wrong with my code?

I also get this error message “NullReferenceException: Object reference not set to an instance of an object PauseScript.Update () (at Assets/MyFolder/My Scripts/PauseScript.js:27)”

#pragma strict

  var pauseCanvas : Canvas;
  var isPause = false;

function Start()
{
    Screen.lockCursor = true;
    Cursor.visible = false;
}

function Update()
{
  if( Input.GetKeyDown(KeyCode.Escape))
  {
    isPause = !isPause;
    if(isPause) 
    {
    Time.timeScale = 0;
    pauseCanvas.enabled = true;
    }
    else 
    {
    Time.timeScale = 1;
    pauseCanvas.enabled = false;
    }
    (gameObject.Find("First Person Controller").GetComponent("MouseLook") as MonoBehaviour).enabled = false;
    (gameObject.Find("Main Camera").GetComponent("MouseLook") as MonoBehaviour).enabled = false;
    pauseCanvas.enabled = true;
    Time.timeScale = 0;
    Screen.lockCursor = false;
    Cursor.visible = true;
  }
}

function ResumeGame()
{

}

The reason why you get an error is because MouseLook is not a class derived from MonoBehaviour. This will fix you problem

#pragma strict

var pauseCanvas : Canvas;
var isPause = false;

function Start()
{
    Screen.lockCursor = true;
    Cursor.visible = false;
    if (pauseCanvas != null)
    {
        pauseCanvas.gameObject.SetActive(false);
        pauseCanvas.enabled = false;
    }
}

function Update()
{
    if( Input.GetKeyDown(KeyCode.Escape))
    {
        isPause = !isPause;
        if(isPause) 
        {
            Time.timeScale = 0;
            pauseCanvas.enabled = true;
            Screen.lockCursor = true;
            Cursor.visible = true;
        }
        else 
        {
            Time.timeScale = 1;
            pauseCanvas.enabled = false;
            Screen.lockCursor = false;
            Cursor.visible = true;
        }

        if (pauseCanvas != null)
        {
            if (GameObject.Find("First Person Controller") != null)
            {
                GameObject.Find("First Person Controller").SetActive(!isPause);
            }
            pauseCanvas.enabled = isPause;
            pauseCanvas.gameObject.SetActive(isPause);
        }
    }
}

function ResumeGame()
{
}