已编辑:
你好,我有一个网格
Vector2[][] grid;
我想获得那些价值
在字典中像这样
Vector2.up => [[0][1],[0][2],[0][3],[0][4],[0][5]]
Vector2.left=> [[1][0],[2][0],[3][0],[4][0],[5][0]]
Vector2.right=> [[1][6],[2][6],[3][6],[4][6],[5][6]]
Vector2.down=> [[6][1],[6][2],[6][3],[6][4],[6][5]]
我这样做:
void GetSpawnablePosition() {
Vector2[] coordX = { Vector2.up, Vector2.down };
Vector2[] coordY = { Vector2.left, Vector2.right };
for (int i = 0; i < coordX.Length; i++)
{
Vector2[] newArray = new Vector2[enemyGrid.grid[0].Length - 2];
if (coordX[i] == Vector2.up)
System.Array.Copy(enemyGrid.grid[0], 1, newArray, 0, enemyGrid.grid[0].Length - 2);
if (coordX[i] == Vector2.down)
System.Array.Copy(enemyGrid.grid[enemyGrid.grid[0].Length - 1], 1, newArray, 0, enemyGrid.grid[0].Length - 2);
spawnablePosition.Add(coordX[i], newArray);
}
for (int i = 0; i < coordY.Length; i++)
{
Vector2[] newArray = new Vector2[enemyGrid.grid.Length - 2];
if (coordY[i] == Vector2.right)
System.Array.Copy(enemyGrid.grid, 1, newArray, 0, enemyGrid.grid.Length - 2);
if (coordY[i] == Vector2.left)
System.Array.Copy(enemyGrid.grid, enemyGrid.grid.Length - 1, newArray, 0, enemyGrid.grid.Length - 2);
spawnablePosition.Add(coordY[i], newArray);
}
Debug.Log(spawnablePosition);
}
但是我得到ArgumentException: length
,我知道我的第二个可能已经破了,我正在努力找到一个好办法......但我现在总是失败
是不是有最简单的方法来完成我的任务,因为真的,我很困惑,我看到了Linq但显然团结不能使用它? (我添加了使用Systen.Linq)但是当我做array.Where()它说错误。