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.

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.