- Home /
Disabling a script .
Hey guys i want to disable the script which is attached to a prefab. I am trying to use. go.Destroy(GetComponent("Script"));
which is not working and not disabling the script. And other is go.GetComponent("Script").enabled="false";
.But the second one gives me error :`"Enabled is not a member of 'UnityEngine.Component'"` . Can any one help me with this.
is that script you're trying to deactivate called "Script"? Are you using javascript or c#?
I'm thinking you might have to cast the result or your GetComponent before calling the enabled function.
yes its the script that i am trying to deactivate.and i am using javascript.!
Answer by robertbu · Aug 06, 2013 at 01:16 PM
I assume you are asking about Javascript. You want:
go.GetComponent(Script).enabled=false;
When you specify a string parameter, the compiler does not know the type. It defaults to 'Component' which does not have an 'enabled'.
works like charm.. thanks @robertbu .. u came once again to my rescue.!
Your answer
![](https://koobas.hobune.stream/wayback/20220613111634im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Toggling a script on/off using the keyboard? 2 Answers
Enabling/Disabling Multiple Tagged objects 1 Answer
enable/disable specific components 3 Answers
Disable the part of the gameobject 2 Answers
Disable a script on another game object 2 Answers