【发布时间】:2018-07-31 13:41:23
【问题描述】:
我有 35 个 Tile 对象,我试图将它们放入 2D 数组(和列表)中,但在填充数组时我不断收到 IndexOutofRange 错误。我使用的代码是:
private Tile[,] AllTiles = new Tile[5,7];
private List<Tile> EmptyTiles = new List<Tile>();
// Use this for initialization
void Start () {
Tile[] AllTilesOneDim = GameObject.FindObjectsOfType<Tile> ();
foreach (Tile t in AllTilesOneDim) {
// Fill 2D Array AllTiles
AllTiles [t.indRow, t.indCol] = t;
// Fill List with all tiles
EmptyTiles.Add (t);
}
}
我应该注意,每个 Tile 对象都包含一个 indRow 0-4 之间的 int 和一个 indCol 0-6 之间的 int。
【问题讨论】: