c# - 根据数组统一的值从脚本更改按钮的颜色
问题描述
所以我有一个包含 100 个值和 100 个按钮的布尔数组,如果它在数组中的相应值是真的,我想要一个按钮有一个颜色,如果它是假的,我希望一个按钮有一个颜色。我试过这个:
public Button buton;
public Image imagine;
public int lvl;
void Start()
{
buton = this.GetComponent<Button>();
imagine = this.GetComponent<Image>();
}
void Awake()
{
if(Storage.lvls[lvl] == true || lvl == 0)
{
buton.interactable = true;
imagine.color = new Color(255, 134, 32, 1);
}
else
{
buton.interactable = false;
imagine.color = new Color(2, 0, 46, 170/255);
}
}
我写this
是因为我想将它作为组件添加到特定按钮。
我收到这个错误NullReferenceException: Object reference not set to an instance of an object butoane.Awake () (at Assets/Scripts/butoane.cs:26)
解决方案
推荐阅读
- rundeck - 是否可以将 Rundeck 徽标替换为社区 docker 映像中的自定义徽标?
- vue.js - Bootstrap Vue 更改活动按钮颜色
- python - Python:如何使用 MPI 并行化一个简单的循环
- graphics - B样条曲线上的最近点?
- javascript - 升级到 Snowpack 3 后找不到文件
- arangodb - 无法从数据集中提取对象值以进行比较或应用过滤器
- php - 供应商/lcobucci/jwt/src/Configuration.php 上的 Laravel 8 错误
- node.js - 连接时套接字console.log()不显示
- typescript - 为什么将类型改装到无类型的东西上需要一个新的 npm 包?
- javascript - 基于给定数组减少 javascript 对象中的键值对