disable script, how to?

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:

  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)

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

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

any help appreciated

Use enabled:

GetComponent(xxx).enabled = false;

hmm it doesnt work

Disables script EndLevel in the same gameobject:

function Start(){

	GetComponent(EndLevel).enabled = false;
}

Disables script EndLevel in another gameobject:

var anotherGameObject;
var anotherGameObjectScript;

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

}}

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??

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

–Eric

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

Use a line of code like

if (!enabled) return;

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

–Eric

great, that does a trick!
very slick move :smile: