Search Unity

How to disable a button?

Discussion in 'UGUI & TextMesh Pro' started by MrDude, Aug 25, 2014.

  1. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    I noticed there are Normal, Highlighted, Pressed and Disabled colours for buttons but how does one actually set a button to disabled so that colour shows up o the disabled sprite loads?

    myButton.enabled = false makes the button not render at all, not show in a "disabled" colour so how then?

    Thanks
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Set interactable on the button component to false
     
    aloften, moaviv, Nephtis and 6 others like this.
  3. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    interactable. Brilliant. :) thanks a bunch :)
    All too easy :)
     
    nicemiceinice likes this.
  4. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    This would make the button non-clickable though, right?
    Is there a way to get that color without making the button non-clickable?

    Or is the best option just to change the color of the normal state?
     
  5. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    It doesn't really make sense for a button to be both 'disabled' and 'clickable' at the same time, so yeah, I'd just change the color of the normal state.
     
  6. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    FOLLOW UP :)

    What's the proper code (Javascript version) for changing the color? The code below is not proper.

    Code (csharp):
    1. shipButtons[shipNumber].GetComponent(UI.Button).normalColor = Color(0.5,0.5,0.5,0.5);