void Awake() { Node = GameObject.Find("Node"); NodeWall = GameObject.Find("NodeWall"); enemyTransform = transform.parent.gameObject.transform.parent.transform; //according to the scene w = 30; h = 30; grid = new NodeForMap[w, h]; WallRange = new GameObject("WallRange"); PathRange = new GameObject("PathRange"); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { Vector3 pos = new Vector3(x - 15, -0.8f, y - 5); bool isWall = Physics.CheckSphere(pos, NodeRadius, Layer); grid[x, y] = new NodeForMap(isWall, pos, x, y); if (isWall) { GameObject obj = GameObject.Instantiate(NodeWall, pos, Quaternion.identity) as GameObject; obj.transform.SetParent(WallRange.transform); } } } }
public List <NodeForMap> GetNeibours(NodeForMap node) { List <NodeForMap> list = new List <NodeForMap>(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 && j == 0) { continue; } int x = node.x + i; int y = node.y + j; if (x < w && x >= 0 && y < h && y >= 0) { list.Add(grid[x, y]); } } } return(list); }