How do you enable/disable a child object individually? C#

I want to be able to enable/disable child objects individually using (possibly) gameObject.SetActive(false); and gameObject.SetActive(true);
in Unity 4.
I want to be able to cycle through a couple of game objects that are children of a larger object. The goal is to have a spaceship with multiple guns that are in one spot on the ship. Pressing tab (for example) would cycle through, say, three different weapons. Is there a simple way to do this? Each gun would have its own particle effects, physics, animations and sounds that would need to be disabled/enabled as well. Thanks in advance.

I think the answer is a little more advanced than simply setting all objects in a hierarchy inactive. When you use the SetActive() method you also toggle the visibility of the game object - it doesn’t seem right to me having guns disappear!

Here’s how I’d do it:

  1. One game object on the ship needs to act as the parent of the guns
  2. Each gun object has a component class, for example ShipGun
  3. Each ShipGun has a boolean that holds whether it can be fired and a pointer to an “on” state particle effect attached to it
  4. Finally each ShipGun should have its own on/off method(s) which toggle “canFire” (or whatever) and use SetActive(canFire) on its particle effect

You should get the list of guns with GetComponentsInChildren() and refresh it only if the guns are changed. Then you can rotate the active one by walking through this list. Pseudo-code:

ShipGun[] guns = gunMount.GetComponentsInChildren<ShipGun>();
int activeGun = 1;
for(int i=0;i<guns.Length;i++)
{
	if(i == activeGun)
	{
		guns*.ToggleState(true);*

_ guns*.canFire = true;_
_
} else {_
_ guns.ToggleState(false);
guns.canFire = false;
}
}*_