Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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
unityunity