- Home /
Disable Object Leave Script Running
Hi Everyone, I would like to have an object disabled for 5 seconds. I used the following JS: gameObject.active = false; yield WaitForSeconds(5); gameObject.active = true;
But it seems that the script stops running as soon as active is set to false. Could someone please confirm this or is it just some other bug in my script. Also, setting the gameObject to inactive for some reason isn't making my object invisible. The models (there are 2) for my object are children of it so I don't get why the renderers aren't being disabled. I also tried doing gameObject.Find("MiniMap Icon").renderer.enabled = false;
but that returned an error about no renderer being attached to gameObject MiniMap Icon. One last thing, if the script stops running immediately when gameObject.active is set to false, could someone suggest a way to reenable it after 5 seconds please?
Answer by Eric5h5 · Dec 30, 2010 at 02:11 AM
Yes, the point of a deactivated object is that it's not active (no rendering, scripts running, etc.). Making an object inactive only makes that object inactive, not children, which are separate objects. You can use GameObject.SetActiveRecursively for that. If you get an error about no renderer attached, that means exactly what it says (that object has no renderer), so use a different object that does have a renderer. You can re-enable inactive objects from a different object that's not inactive.