I’m getting an out of range error almost every time the last line is called when locationX & locationY are at the edge of the array.
gameSpaces is a 5x5 array of GameObjects. 0,0 is the bottom left position, 4,4 is the top right.
switch(walkdirection){
case WalkDirection.Up:
if(locationY < gameController.gameSpaces.GetLength(1)){
locationY++;
}
break;
case WalkDirection.Down:
if(locationY > 0){
locationY--;
}
break;
case WalkDirection.Left:
if(locationX > 0){
locationX--;
}
break;
case WalkDirection.Right:
if(locationX < gameController.gameSpaces.GetLength(0)){
locationX++;
}
break;
}
transform.position = gameController.gameSpaces[locationX, locationY].transform.position;