Disable MouseLook script FPC

I want to make a menu inside the game. So if you pres escape a window appears with buttons. When the window appears the mouselook script from the First Player Controller must be disabled. I found and used this script, what seems to be oke. but I get a error when i press escape

NullReferenceException: Object reference not set to an instance of an object Gui.window.Update () (atAssets\script\Gui_window.js:25)

    var SkinWindow: GUIStyle;
    var SkinTitle : GUIStyle;
    var SkinButton: GUIStyle;
    private var doWindow0 : boolean= false;
    private var gameobj : GameObject;
    private var mouseL : MouseLook;
    private var cam : GameObject; 
    private var mouseL2 : MouseLook;
    private var windowRect0= Rect(50,50,300,300);

    function Awake() 
    { 
       gameobj =GameObject.Find("First Person Controller"); 
       mouseL = gameobj.GetComponent(MouseLook); 
       cam = gameobj.Find("First Person Controller/Main Camera"); 
       mouseL2 = cam.GetComponent(MouseLook); 
    }

    function Update ()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            doWindow0= !doWindow0;
            mouseL.enabled=!mouseL.enabled;
            mouseL2.enabled=!mouseL2.enabled;
        }
    }

    function OnGUI () 
    {
        if(doWindow0)
        GUI.Window(0,Rect(300,10,500,500),StartWindow0,"CONTROLS",SkinWindow);
    }

    /*GUIWindow content*/
    function StartWindow0 (windowID : int)
    {
        GUI.Label (Rect (50,50,350,100), "OM ROND TE LOPEN, GEBRUIK PIJLTOETSEN",SkinTitle);
        doWindow0=GUI.Toggle(Rect(400,400,76,76),doWindow0,"EXIT",SkinButton);  
        GUI.DragWindow(Rect(0,0,10000,10000));
    }

I got the standard First person controller from the standard assets screencap hierarchy

please help!

Make a static variable:

Static var isGamePaused : Boolean = false;

Then put this inside your update function:

if(Input.GetKeyDown(KeyCode.Escape)){
      if(!isGamePaused){
            isGamePaused = true;
            GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = false;
            GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false;
      }
}

Keep in mind that this will only disable the MouseLook. To re-enable it use the same idea in reverse with a different If statement. I.E.

if(Input.GetKeyDown(KeyCode.Escape)){
      if (isGamePaused){
            isGamePaused = false;
            GameObject.Find("First Person Controller").GetComponent("MouseLook").enabled = true;
            GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;
      }
}

Haha i felt stupid when i figured this out. There’s two MouseLook scripts, one for your main camera and one for your character controller (typically). Make a script that has this:

function Update () {
if (Input.GetKeyUp(KeyCode.Escape)) {
    var mouseLook = GetComponent.<MouseLook>();
    mouseLook.enabled = !mouseLook.enabled;
}

}

Then add it to both the main camera and your character controller.

This worked for me, hope it works for you

(i know its 2012, this is for anybody else having this problem)