# Problem when disabling the MouseLook script

**URL:** https://discussions.unity.com/t/problem-when-disabling-the-mouselook-script/402586
**Category:** Scripting
**Tags:** Scripting
**Created:** [November 27, 2009, 5:59pm UTC](https://discussions.unity.com/t/problem-when-disabling-the-mouselook-script/402586 "2009-11-27T17:59:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_77443035](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon\_77443035](https://discussions.unity.com/u/anon_77443035)
#### Post date: [November 27, 2009, 5:59pm UTC](https://discussions.unity.com/t/problem-when-disabling-the-mouselook-script/402586/1 "2009-11-27T17:59:25Z")

</div>

So here is my problem, i hava GUI menu that when i toggle it when i press Escape i want the mouse and everything to freeze. I’ve made a script that disables the whole script using the .enable = false. But the camera still rotates along the X axis, while the Y axis is frozen. And the “check box” next to the script in Camera is unchecked…

here is my code:

```auto
var mouseSource : GameObject;

function Update() {
	var mouseLook = mouseSource.GetComponent("MouseLook");
	if (GUIGroup.menuOn == true) {
		mouseLook.enabled = false;
		Time.timeScale = 0;
		return;
	}
	else if (GUIGroup.menuOn == false){
		mouseLook.enabled = true;
		Time.timeScale = 1;
		return;
	}
}

```

Maybe its just me, but imo the camera shouldnt be able to move if the script is disabled.

---

<div class="post-metadata">

### Author: ![anon\_77443035](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@anon\_77443035](https://discussions.unity.com/u/anon_77443035)
#### Post date: [November 27, 2009, 7:35pm UTC](https://discussions.unity.com/t/problem-when-disabling-the-mouselook-script/402586/2 "2009-11-27T19:35:19Z")

</div>

Ok I solved it, aparently the FPS controller from the Standard Assets have one MouseLook in the FPS Controller and one on the Main Camera.

New problem:

I get an error: Object reference not set to an instance of an object.

here is the code:

```auto
var target : GameObject;
var mouseLook = target.GetComponent("MouseLook");

function Update() {
   if (GUIGroup.menuOn == true) {
      mouseLook.enabled = false;
      Time.timeScale = 0;
      return;
   }
   else if (GUIGroup.menuOn == false){
      mouseLook.enabled = true;
      Time.timeScale = 1;
      return;
   }
}

```

---

<div class="post-metadata">

### Author: ![anon\_41289261](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@anon\_41289261](https://discussions.unity.com/u/anon_41289261)
#### Post date: [January 3, 2010, 5:56pm UTC](https://discussions.unity.com/t/problem-when-disabling-the-mouselook-script/402586/3 "2010-01-03T17:56:08Z")

</div>

i also has a same problem, but it already solved now,  
here is my code :

```auto
mouseLook = this.GetComponent("MouseLook"); 
mouseLook.enabled=true;

```

you can put it in the same gameObject, so the script only need to look for the component in the same object.

- sory for my bad english [wovie] :lol:
