how do i hide an complex 3dModel with its children and grandchildren?

i am trying to make a script that will show a 3dmodel (with all of its children and grandchildren ) and hide the other 2 3dmodels (with their children and grandchildren)

this is how far i have gotten, even though im not really a coder. the code works on unity primitives but not any of my complex environment models.

`var object1 : GameObject; var object2 : GameObject; var object3 : GameObject;

function Start () {
   object1.gameObject.active = true;
   object2.gameObject.active = false;
   object3.gameObject.active = false;

}

function Update () {
   if (Input.GetKeyDown ("x")){
      object1.gameObject.active = true;
      object2.gameObject.active = false;
      object3.gameObject.active = false;
   }
   if (Input.GetKeyDown ("z")){
      object1.gameObject.active = false;
          object2.gameObject.active = true;
      object3.gameObject.active = false;
    }
       if (Input.GetKeyDown ("c")){
      object1.gameObject.active = false;
          object2.gameObject.active = false;
      object3.gameObject.active = true;
}}`

Hello, I have encountered the same problem when I had to enable a FPS controller and then disable it and all its children's to enable a third person controller.

first you could use:

Object.active = false; // (or = true to enable)

but you would need to do that for all the "pieces of the object".

the second alternative would be using:

Object.SetActiveRecursively(true); // (or false to disable)

that would make the code simpler and smaller as well. I made a post in my recently made blog about this.

Blog's Link

Hope it helps :)