【发布时间】:2017-03-05 01:53:18
【问题描述】:
我正在尝试制作一个“东西”,通过使用播放器首选项整数从数组中检查/取消选中特定对象的可交互复选框。我遇到的问题是我似乎无法从数组中引用特定对象,请帮忙。
这里有一些脚本:
//This part is from the Start function.
for (int i = 0; i < buttons.Length; i++) {
if (PlayerPrefs.GetInt("button" + i) == null) {
PlayerPrefs.SetInt("button" + i, 1);
}
if (PlayerPrefs.GetInt("button" + i) == 1) {
button.interactable = true;
} else {
button.interactable = false;
}
}
void Update () {
for (int i = 0; i < buttons.Length; i++) {
if (PlayerPrefs.GetInt("button" + i) == 0) {
button.interactable = false;
}
}
}
您可以看到 button.interactable = true/false 的区域是我遇到问题的地方。
【问题讨论】:
-
您是否考虑过在类中只使用一个按钮实例并将其显示在表单上,而不是在类中使用整数变量?这样你就可以通过类的实例与按钮进行交互了。
标签: c# arrays boolean components