- Home /
Disable / enable script
Wanted to know how to disable / enable script on a gameObject using a boolean variable (true = on and false = off).
Thanks.
Answer by cynixway · Oct 06, 2012 at 12:29 PM
If you want to disable the script,get the script component. Like:
SomeScript someScript=gameObject.GetComponet();
someScript.enable=false;//disable;
someScript.enable=true;//enable;
And in the script,you can write like:
this.enable=false;
this.enable=true;
Answer by hvilela · Oct 06, 2012 at 12:48 AM
enable = myBooleanVariable;
Sure. This code disable the same sprit where the enable/disable code is. If you want to enable/disable a different sprit use GetComponent.
GetComponent(YourComponentName).enable = myBooleanVariable;
Your answer
Follow this Question
Related Questions
How would I attached a gameobject to a prefab that is spawned at a specific time? 1 Answer
Trigger script does not work 1 Answer
Help needed on c# code which all of you will find basic apart from me 1 Answer
How can I access a GameObject's script from a prefab? 1 Answer
Accesing another Script on gameObject and asking if it is true. 1 Answer