public void BuildRoads(int gridPosX, int gridPosY) { if (Input.GetMouseButtonDown(0)) { //Start generation _roadGenerator.Start(); _mouseDownPosX = gridPosX; _mouseDownPosY = gridPosY; } if (Input.GetMouseButton(0)) { //Generating _roadGenerator.ClearSavedRoads(); if (_roadGenerator.CanCreateRoad(gridPosX, gridPosY)) { Vector2Int startPos = new Vector2Int(_mouseDownPosX, _mouseDownPosY); Vector2Int endPos = new Vector2Int(gridPosX, gridPosY); List <Vector2Int> path = Map.GetShortestPath(startPos, endPos); foreach (Vector2Int road in path) { _roadGenerator.Generate(road.x, road.y); } } } if (Input.GetMouseButtonUp(0)) { //End generation _roadGenerator.End(); } if (Input.GetMouseButtonDown(1)) { //Cancel generation _roadGenerator.Cancel(); } }