- Home /
gameObject.SetActiveRecursively
Hello all.
I am not sure how to formulate the title since this is really weird. What I am doing is turning a weapon "On" and "Off" with gameObject.SetActiveRecursively(false); and gameObject.SetActiveRecursively(true); But the problem is "disturbing".
Allow me to explain as well is I can. I have this piece of code:
if(CustomController.inWorthog)
{
print("Off");
gameObject.SetActiveRecursively(false); // 1. If this is used. 2. If not used
}
if(!CustomController.inWorthog)
{
print("On");
gameObject.SetActiveRecursively(true); // 1. This part wont execute 2. This will execute
}
Which switches the weapon on and off depending on wheater or not the player is "inWorthog", but(and it is a big but) When using gameObject.SetActiveRecursively(false); above in the code the second part do not execute(this part:
if(!CustomController.inWorthog)
{
print("On");
gameObject.SetActiveRecursively(true);
}
but if I leave gameObject.SetActiveRecursively(false); out(commenting it out) the second part second part executes fine. I do not know how to counter this.
Please it would mean a lot to me if you know a fix for this.
Legion, for we are many.
Answer by Dreamblur · Jul 02, 2011 at 10:53 PM
When you run this line:
gameObject.SetActiveRecursively(false);
you are deactivating your game object, which means this script, being attached to the game object that was deactivated, will stop running as well.
Thank you. Hah I did not think of that. Thank you for your time. :)
Your answer
Follow this Question
Related Questions
Deactivate Instantiated child Objects not working 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Object.operator bool evaluates oddly 1 Answer
SetActiveRecursively not activating children 2 Answers
Unity 4 SetActive - SetActiveRecursively parent-child trouble 2 Answers