所以我想出了如何通过下面的代码制作可在检查器中查看的2D数组。
[System.Serializable]
public class QuestPhase {
[HideInInspector]
public string name;
public int[] Phase = new int[5];
}
public QuestPhase[] questPhase = new QuestPhase[5];
这很好用,但我正在试图弄清楚如何通过脚本访问这些信息,我无法理解。
questVariable = questPhase[1,1];
返回“预期1索引,得2”的错误,只使用一个索引就可以“无法将类型QuestPhase转换为int类型”。我确定答案很明显,但如果有人能为我解答,我会非常感激。
答案 0 :(得分:0)
当它显示expected 1 index, got 2
时,因为您的questPhase
变量是QuestPhase[]
- 即QuestPhase
s的一维数组。您只需按questPhase[1]
索引它。
此时,您似乎正在尝试将questPhase[1]
用作int
,即使它实际上是Phase
类型。您可能希望questPhase[1].Phase[1]
获取第二个QuestPhase
对象,并从中获取第二个Phase
。
questVariable = questPhase[1].Phase[1];