- Home /
Having a game object de-activate itself
To have a script stopped in a game object, is it possible to have the script tell the same game object to deactivate itself?
Answer by Rod-Green · Nov 02, 2011 at 02:51 AM
gameObject.active = false;
or if you want to do it once the script is set to disabled
void OnDisable()
{
gameObject.active = false;
}
Not this will only affect the gameObject the script is attached to.. if you want to apply the effect to all children also
gameObject.SetActiveRecursively(false);
After calling that, would all subsequent lines of your script not be called?
Yes any attached monos and methods will stop being called. Except for OnDestroy or OnEnable, Start etc if the object is destroyed or enabled again respectively.
Your answer
Follow this Question
Related Questions
Deactivate an object - and all scripts in that object deactivated? 1 Answer
Children of DualTouchControls prefab keep being forced to active 0 Answers
Referencing children of an instantiated object. 1 Answer
activating and deactivating gameObject on keypress? 1 Answer
activate object on key press only, otherwise always deactivated! 2 Answers