Deactivate GameObject and Children

I am creating an fps. I need to be able to deactivate the player’s weapon and all children of the weapon. I created the following script to do so.

var weapon : GameObject;

function Start () { }

function Update () {
     if (Input.GetKeyDown (KeyCode.E)) {
          weapon.active = !weapon.active;
     }
}

When I attach the script to the main camera, it does not deactivate the gameobject. How can I fix this?

Weapon.gameobject.active = false;

Be aware that this behaviour will change with Unity 4.0

Here is the release note :

We have changed how the active state of GameObjects is handled. GameObjects active state will now affect child GameObjects, so setting a GameObject to inactive will now turn the entire sub-hierarchy inactive. This may change the behavior of your projects. GameObject.active and GameObject.SetActiveRecursively() have been deprecated. Instead, you should now use the GameObject.activeSelf and GameObject.activeInHierarchy getters and the GameObject.SetActive() method.

If you want to toggle between enabled and disabled with just one GameObject, you can do this:

gameObject.active = !gameObject.active;

If you want to toggle a GameObject and all of its children, you can do this:

gameObject.SetActiveRecursively(!gameObject.enabled);