disable a component?

hi…

how can i disable a script component from a gameObject?

for instance… i have the fpc prefab, it has a fpcwalker script component, … but if i press escape button, the script must to be disabled…

don’t need to know the Input event… just the event for disabling component…

something like this:

function Update(){
if (Input.GetKeyDown("escape")){
   //disable script Component from playerGameObject
}
}

Thanks.

I believe there’s an ‘enabled’ flag that you can use for this.

do you mean with booleans… will try
thanks.!

I’m at work now… so maybe i get confused, but i think script components can be enable/disable… but i guess you must use “active” not “enabled”.

What are you referring to exactly? Unity components have an ‘enabled’ field, but they don’t have an ‘active’ field that I’m aware of.

GameObject.GetComponent(rigidbody).enabled = false;

I am having troubles with that too I may just have to develop a workaround.

You should be able to just use ‘GetComponent(script).enabled = false’.

The ‘enabled’ value comes from behing a Behaviour, so your script should extend MonoBehaviour.

active is used to disable/enable entire GameObjects… enabled is used to enable/disable components.