public void CreateMap() { int tileID = 0; foreach (int x in Enumerable.Range(0, mapSize)) { foreach (int y in Enumerable.Range(0, mapSize)) { GameObject tile = (GameObject)Instantiate(mapTileSprite, new Vector3(x, y, 0f), Quaternion.identity); var vertex = new Vertex(tile, tileID); mapTiles[x, y] = vertex; mapGraph.AddVertex(vertex); tileID++; } } foreach (int x in Enumerable.Range(0, mapSize)) { foreach (int y in Enumerable.Range(0, mapSize)) { if (x > 0) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x - 1, y])); } if (y > 0) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x, y - 1])); } if (x < mapSize - 1) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x + 1, y])); } if (y < mapSize - 1) { mapGraph.AddDirectedEdge(new Edge <Vertex>(mapTiles[x, y], mapTiles[x, y + 1])); } } } }