简体   繁体   中英

How to change a UI.Button disabled color on runtime?

I want to change the opacity of my buttons disabled color with code in this exact loop so I was wondering how? Maybe sommething like how I disabled interactability. It should be done to tictactoeSpaces too.

        for(int i = 0; i < tictactoeSpaces.Length; i++)
        {
            tictactoeSpaces[i].interactable = false;
        }

Does it need to be via code?

You actually can configure that in the Inspector of the Button component

在此处输入图像描述

If you really need to do it on runtime you can change it via the Button.colors property like eg

var button = tictactoeSpaces[i];
var colors = button.colors;
var disabledColor = colors.disabledColor;
disabledColor.a = /*NEWALPHA e.g.*/ 0.2f;
colors.disabledColor = disabledColor;
button.colors = colors;

button.interactable = false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM