我正在获取IndexOutOfRangeException:数组索引超出范围。 Grid.updateGrid()(在Assets / Sripts / Grid.cs:59处) Grid.MPGridCreate()(在Assets / Sripts / Grid.cs:43处)Grid.Awake()(在Assets / Sripts / Grid.cs:27处)出现此sript错误,并且不知道为什么在我的统一pacman项目游戏中。 / p>
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Grid : MonoBehaviour {
public GameObject bottomLeft,topRight;
public GameObject start,goal;
Node[,]myGrid;
public List<Node> path;
public LayerMask unwalkable;
int xStart, zStart;
int xEnd, zEnd;
int vbells,hbells;
int bellWidth = 1;
int bellHeight = 1;
void Awake()
{
MPGridCreate();
}
void MPGridCreate()
{
xStart = (int)bottomLeft.transform.position.x;
zStart = (int)bottomLeft.transform.position.z;
xEnd = (int)topRight.transform.position.x;
zEnd = (int)topRight.transform.position.z;
hbells = (int)((xEnd - xStart) / bellWidth);
vbells = (int)((zEnd - zStart) / bellHeight);
myGrid = new Node[hbells + 1, vbells];
updateGrid ();
}
//updategrid
public void updateGrid()
{
for (int i = 0; i <= hbells; i++)
{
for (int j = 0; j <= vbells; j++)
{
bool walkable = !(Physics.CheckSphere(new Vector3(xStart + i, 0, zStart + j),0.4f, unwalkable));
myGrid[i,j] = new Node(i, j, 1, walkable);
}
}
}