Kejsi Struga
Kejsi Struga

Reputation: 560

Disable button in unity without changing its transparency

I have noticed that when I set the interactable property of button to false the button alpha decreases. Does anybody have knowledge on how to achieve this in Unity .

 myButton.interactable = false;

It would be immensely helpful if you could help !

Thank you !

Upvotes: 0

Views: 3114

Answers (1)

Hellium
Hellium

Reputation: 7356

You have to change the "Disabled Color" of the Button component. Check the alpha value. enter image description here

In order to change it by code :

// Unfortunately, you can't do button.colors.disabledColor.a = 1 ;
UnityEngine.UI.ColorBlock colors = button.colors ;
Color disabledColor = colors.disabledColor ;
disabledColor.a = 1 ;
colors.disabledColor = disabledColor ;
button.colors = colors ;

Upvotes: 7

Related Questions