在C#中引用数组中对象的组件

时间:2016-10-23 02:19:31

标签: c# arrays boolean components

我试图制作一个""通过使用播放器pref整数从数组中检查/取消选中特定对象的可交互复选框。我遇到的问题是我似乎无法从数组中引用特定对象,请帮忙。

这是一些脚本:

//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的区域是我遇到问题的地方。

1 个答案:

答案 0 :(得分:2)

如果您没有在其他地方定义button;我假设您缺少数组索引访问器的概念;您可能希望使用buttons[i]代替button

相关问题