简体   繁体   English

如何在运行时更改 UI.Button 禁用颜色?

[英]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. tictactoeSpaces 也应该这样做。

        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您实际上可以Button组件的 Inspector 中配置它

在此处输入图像描述

If you really need to do it on runtime you can change it via the Button.colors property like eg如果您确实需要在运行时执行此操作,您可以通过Button.colors属性更改它,例如

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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