Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

how to hide and unhide UI button?

Discussion in 'UGUI & TextMesh Pro' started by jim_bbq, Jul 3, 2015.

  1. jim_bbq

    jim_bbq

    Joined:
    Sep 30, 2013
    Posts:
    8
    I have a button which is initially set to be invisible and I want to unhide it with a script

    I tried restart_btn.enabled = true; but it does not work.

    any thought> thanks!
     
  2. Hasanaj

    Hasanaj

    Joined:
    Jun 22, 2015
    Posts:
    21
    Ok, use SetActive(false) or SetActive(true);
    In your case, if you have a variable that stores the button(restart_btn) then you could do :

    Code (CSharp):
    1. public void hide(){
    2.       restart_btn.SetActive(false);
    3. }
    4. public void show(){
    5.       restart_btn.SetActive(true);
    6. }
    This worked for me :)