Search Unity

visibility switch for GameObject

Discussion in 'Scripting' started by mmwizard, Jul 13, 2009.

  1. mmwizard

    mmwizard

    Joined:
    Mar 27, 2009
    Posts:
    65
    Hello,

    I am making a scene where the user can choose between 3 options. Each of these options is a GameObject with a few childnodes. And what i wand is in scripting to make the parent GameObject visible or not.
    Here is my code

    Code (csharp):
    1. void Start () {
    2.         opt1 = GameObject.Find("AB01");
    3.         opt2 = GameObject.Find("AB02");
    4.         opt2 = GameObject.Find("AB03");
    5.     }
    6.  
    7.     void OnGUI () {
    8.         toolbarInt = GUI.Toolbar(r, toolbarInt, toolbarStrings);
    9.  
    10.         if (GUI.changed)
    11.         {
    12.             opt1.active = false;
    13.             opt2.active = false;
    14.             opt3.active = false;
    15.             switch (toolbarInt)
    16.             {
    17.                 case 1:
    18.                     opt1.active = true;
    19.                     break;
    20.                 case 2:
    21.                     opt2.active = true;
    22.                     break;
    23.                 default:
    24.                     opt3.active = true;
    25.                     break;
    26.             }
    27.         }
    28.     }
    Problem is that in my Hierarchy view the do go on and of but in the view they are still visible.
    Now i think its because i need to turn off all the childnodes as wel. But i like to now if there is a easier way to do this?

    Thanx in advance...
     
  2. phuzzy

    phuzzy

    Joined:
    Feb 12, 2009
    Posts:
    31