簡體   English   中英

如何在運行時更改 UI.Button 禁用顏色?

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

我想用這個精確循環中的代碼更改按鈕禁用顏色的不透明度,所以我想知道怎么做? 也許就像我如何禁用交互性一樣。 tictactoeSpaces 也應該這樣做。

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

是否需要通過代碼?

您實際上可以Button組件的 Inspector 中配置它

在此處輸入圖像描述

如果您確實需要在運行時執行此操作,您可以通過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