public void FindNeighbors() { float x = pos [1]; float y = pos [0]; string tileName; if ((pos [0] % 2) == 0) { y--; x--; tileName = "HexTile [" + y + "," + x + "]"; if (pos [0] != 0 && pos [1] != 0) { NW_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } x++; tileName = "HexTile [" + y + "," + x + "]"; if (pos [0] != 0) { NE_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } y++; x++; tileName = "HexTile [" + y + "," + x + "]"; if (pos [1] != 9) { E_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } y++; x--; tileName = "HexTile [" + y + "," + x + "]"; SE_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); x--; tileName = "HexTile [" + y + "," + x + "]"; if (pos [1] != 0) { SW_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } y--; tileName = "HexTile [" + y + "," + x + "]"; if (pos [1] != 0) { W_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } x++; } else { y--; tileName = "HexTile [" + y + "," + x + "]"; NW_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); x++; tileName = "HexTile [" + y + "," + x + "]"; if (pos [1] != 9) { NE_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } y++; tileName = "HexTile [" + y + "," + x + "]"; if (pos [1] != 9) { E_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } y++; tileName = "HexTile [" + y + "," + x + "]"; if (pos [1] != 9 && pos[0] != 9) { SE_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } x--; tileName = "HexTile [" + y + "," + x + "]"; if (pos [0] != 9) { SW_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } y--; x--; tileName = "HexTile [" + y + "," + x + "]"; if (pos [1] != 0) { W_Tile = GameObject.Find (tileName).GetComponent<TestHexTile> (); } x++; } }
public void Move(int dir) { bool validMove = ValidMove (dir); if (validMove && movement != 0) { tile.character = null; switch (dir) { case 1: tile.NW_Tile.character = this.gameObject; tile = tile.NW_Tile; break; case 2: tile.NE_Tile.character = this.gameObject; tile = tile.NE_Tile; break; case 3: tile.E_Tile.character = this.gameObject; tile = tile.E_Tile; break; case 4: tile.SE_Tile.character = this.gameObject; tile = tile.SE_Tile; break; case 5: tile.SW_Tile.character = this.gameObject; tile = tile.SW_Tile; break; case 6: tile.W_Tile.character = this.gameObject; tile = tile.W_Tile; break; default: break; } moving = true; movement = movement - tile.mov_cost; } if (movement == 0) { Active = false; } }