Scripts are disabled but still execute actions!??

Hi there,

Ok, so in my simple test scene I have 3 objects a Cylinder a Capsule and a FPS controller.

What I am trying to do is: the Cylinder has a script attached so when triggered, it turns off the Capsule:

 function OnTriggerEnter (other : Collider){
  
caps = GameObject.Find("Capsule");

caps.GetComponent(MeshRenderer).enabled = false;

print ("hide capsule");

}

Great, that works.

BUT! When i uncheck that script in the Inspector, and run the game the code is still executed and the Capsule dissapears, even though the script is clearly disabled?

Am i missing somthing here?

Cheers

OnTriggerEnter is a message that is sent so it being sent is a side effect of the gameobject itself being active.

if you want to cull it out when its disabled add:

if(this.enabled){
do stuff
}

Yes Excellent, thanks you! :slight_smile:

Here is the working code just for reference:

function OnTriggerEnter (other : Collider) {

if (GetComponent(hidecaps).enabled){
  
caps = GameObject.Find("Capsule");

caps.GetComponent(MeshRenderer).enabled = false;

print ("hide capsule");

}
}

By design, disabled scripts only have functions like Update and OnGUI prevented from running, but not other functions.

–Eric