ernbot
February 22, 2011, 10:39am
1
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
}
ernbot
February 22, 2011, 11:46am
3
Yes Excellent, thanks you!
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");
}
}
Eric5h5
February 22, 2011, 7:17pm
4
By design, disabled scripts only have functions like Update and OnGUI prevented from running, but not other functions.
–Eric