Search Unity

How do I disable&hide the buttons in my Canvass/Menu?

Discussion in 'Scripting' started by Sunniiee, Aug 29, 2015.

  1. Sunniiee

    Sunniiee

    Joined:
    Aug 29, 2015
    Posts:
    6
    For Some Reason the startB, exitB, and optionB UI Buttons does not disappear. However when I create a textUI and then add a Button Component it disappears the way I want it too using the same code. D: Additional question, how do you disable an image too since I'm planning to make a Image UI and disable it.

    Code (CSharp):
    1.     public Canvas OptionMenu;
    2.     public Canvas StartMenu;
    3.     public Button startB;
    4.     public Button exitB;
    5.     public Button optionB;
    6.     public Text GameTitle;
    7.  
    8.     void Start () {
    9.         OptionMenu = OptionMenu.GetComponent<Canvas> ();
    10.         StartMenu = StartMenu.GetComponent<Canvas> ();
    11.         startB = startB.GetComponent<Button> ();
    12.         exitB = exitB.GetComponent<Button> ();
    13.         optionB = optionB.GetComponent<Button> ();
    14.         GameTitle = GameTitle.GetComponent<Text> ();
    15.         OptionMenu.enabled = false;
    16.  
    17.     }
    18.    
    19.     void Update () {
    20.    
    21.     }
    22.  
    23.  
    24.     public void StartPress()
    25.     {
    26.         OptionMenu.enabled = false;
    27.         startB.enabled = false; //does not work the way I want to
    28.         exitB.enabled = false; //does not work the way I want to
    29.         optionB.enabled = false; //does not work the way I want to
    30.         GameTitle.enabled = false;
    31.  
    32.     }
    Any ideas? Thank you so much for any advice. :D
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Use GameObject.SetActive(false).
     
  3. Sunniiee

    Sunniiee

    Joined:
    Aug 29, 2015
    Posts:
    6
    I tried it but it does not work. :(
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    That's odd. As in:

    Code (CSharp):
    1. startB.gameObject.SetActive(false);
     
  5. Sunniiee

    Sunniiee

    Joined:
    Aug 29, 2015
    Posts:
    6
    Thank you!! I just realized that I made a simple mistake.
     
    Kiwasi likes this.