private void AddRoads() { //Bound entity contains pathfinding weights for roads; HashSet <Vector2> connectedVillages = new HashSet <Vector2>(); var tileMap = generator.tileMap; var width = generator.width; var height = generator.height; for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { if (tileMap[i, j] == WorldTextureAtlas.Tiles.Village) { List <Vector2> neighbouringVillages = scanNeighbouringVillages(i, j); foreach (var villageID in neighbouringVillages) { if (connectedVillages.Contains(villageID)) { continue; } List <Vector2> path = pathGrid.FindPathTiles(new Vector2(i, j), villageID, GetComponent <Entity>()); GameObject newRoad = GameObject.Instantiate(linePrefab, new Vector3(0, 0, 0), Quaternion.identity, transform); newRoad.GetComponent <CurveLineRenderer>().ClearVertices(); connectedVillages.Add(villageID); foreach (var roadID in path) { if (connectedVillages.Contains(roadID)) { continue; } if (tileMap[(int)roadID.x, (int)roadID.y] == WorldTextureAtlas.Tiles.Village) { break; } else { tileMap[(int)roadID.x, (int)roadID.y] = WorldTextureAtlas.Tiles.Road; Vector2 worldPos = worldPosFromNode((int)roadID.x, (int)roadID.y); newRoad.GetComponent <CurveLineRenderer>().AddVertex(new Vector3(worldPos.x, worldPos.y, roadZ)); } } } } } } pathGrid.CreateGrid(); generator.UpdateWaterSprites(); }