# disable script, how to?

**URL:** https://discussions.unity.com/t/disable-script-how-to/416431
**Category:** Scripting
**Tags:** Scripting
**Created:** [June 23, 2010, 7:46am UTC](https://discussions.unity.com/t/disable-script-how-to/416431 "2010-06-23T07:46:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pretender](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pretender/32/915043_2.png) [@pretender](https://discussions.unity.com/u/pretender)
#### Post date: [June 23, 2010, 7:46am UTC](https://discussions.unity.com/t/disable-script-how-to/416431/1 "2010-06-23T07:46:56Z")

</div>

i have this highlight script, it is assigned to a lot of objects in the scene, when the mouse is over it multiplies the color component and object gets highlighted, similiar on mouse exit it assigns original color…that works fine, the problem is when i isolate one object i dont want it to highlight any more, so i tried to disable that script…

i tried this:

```auto
  var highlightScript : GameObject;
  
  //in start()
  //GET REFERENCE TO THE HIGHLIGHT SCRIPT
  highlightScript= GameObject.Find("Highlight");	

  //in the function that isolates the object
  highlightScript.active=false;

```

and this doesn’t work

i also tried this:  
(i have properly referenced to the camera, and i can acces the current target corretly, every object have Highlight script attached to it)

```auto
 camScript.currentTarget.GetComponent("Highlight").active=false;

```

this make the whole object to disappear, it definitly does not disable the highlight script!

any help appreciated

---

<div class="post-metadata">

### Author: ![Esa\_1](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@Esa\_1](https://discussions.unity.com/u/Esa_1)
#### Post date: [June 23, 2010, 7:53am UTC](https://discussions.unity.com/t/disable-script-how-to/416431/2 "2010-06-23T07:53:18Z")

</div>

Use enabled:

GetComponent(xxx).enabled = false;

---

<div class="post-metadata">

### Author: ![pretender](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pretender/32/915043_2.png) [@pretender](https://discussions.unity.com/u/pretender)
#### Post date: [June 23, 2010, 9:18am UTC](https://discussions.unity.com/t/disable-script-how-to/416431/3 "2010-06-23T09:18:47Z")

</div>

hmm it doesnt work

---

<div class="post-metadata">

### Author: ![Esa\_1](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@Esa\_1](https://discussions.unity.com/u/Esa_1)
#### Post date: [June 23, 2010, 9:34am UTC](https://discussions.unity.com/t/disable-script-how-to/416431/4 "2010-06-23T09:34:45Z")

</div>

Disables script EndLevel in the same gameobject:

```auto
function Start(){

	GetComponent(EndLevel).enabled = false;
}

```

Disables script EndLevel in another gameobject:

```auto
var anotherGameObject;
var anotherGameObjectScript;

function Start(){
	
	//--- Finds the gameobject
	anotherGameObject = GameObject.FindWithTag("MainCamera");
	//--- Gets the script
	anotherGameObjectScript = anotherGameObject.GetComponent(EndLevel);
	
	anotherGameObjectScript.enabled = false;

}}

```

---

<div class="post-metadata">

### Author: ![pretender](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pretender/32/915043_2.png) [@pretender](https://discussions.unity.com/u/pretender)
#### Post date: [June 23, 2010, 1:15pm UTC](https://discussions.unity.com/t/disable-script-how-to/416431/5 "2010-06-23T13:15:01Z")

</div>

hmmm, at first i thought that it doesnt work, but i investigated further and it seems that your code does disables the script (as i can see in the inspector) but the object still highlights when mouse over?!

i have a lot of objects in the scene with this highlight script on them, in fact i have one game object where all children have this script attached, is that what is causing problem??

---

<div class="post-metadata">

### Author: ![Eric5h5](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/eric5h5/32/44225_2.png) [@Eric5h5](https://discussions.unity.com/u/Eric5h5)
#### Post date: [June 23, 2010, 3:43pm UTC](https://discussions.unity.com/t/disable-script-how-to/416431/6 "2010-06-23T15:43:08Z")

</div>

Disabling a script doesn’t disable all functions (by design), it only disables Update and related functions.

–Eric

---

<div class="post-metadata">

### Author: ![pretender](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pretender/32/915043_2.png) [@pretender](https://discussions.unity.com/u/pretender)
#### Post date: [June 23, 2010, 3:46pm UTC](https://discussions.unity.com/t/disable-script-how-to/416431/7 "2010-06-23T15:46:46Z")

</div>

oh…i need to disable OnMouseEnter, is it possible?

---

<div class="post-metadata">

### Author: ![Eric5h5](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/eric5h5/32/44225_2.png) [@Eric5h5](https://discussions.unity.com/u/Eric5h5)
#### Post date: [June 23, 2010, 4:48pm UTC](https://discussions.unity.com/t/disable-script-how-to/416431/8 "2010-06-23T16:48:40Z")

</div>

Use a line of code like

```auto
if (!enabled) return;

```

so the OnMouseEnter function doesn’t do anything if the script was disabled.

–Eric

---

<div class="post-metadata">

### Author: ![pretender](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/pretender/32/915043_2.png) [@pretender](https://discussions.unity.com/u/pretender)
#### Post date: [June 23, 2010, 5:43pm UTC](https://discussions.unity.com/t/disable-script-how-to/416431/9 "2010-06-23T17:43:29Z")

</div>

great, that does a trick!  
very slick move 😄
