public void SpawnBuilding(int index) { if (gameRules.waveStatus || !CheckBuildingValidity(index) || !CheckRessourcesAvailability(index)) { return; } if (constructionState == ConstructionState.Positioning) { Destroy(selectedBuilding.gameObject); } else { constructionState = ConstructionState.Positioning; } Tile tile = rayCast.GetNearestTileFromCursor(); if (tile != null) { defaultSpawnPosition = tile.tileCenter.position; } selectedBuilding = Instantiate(playerData.availableBuildings[index]); selectedBuilding.Move(defaultSpawnPosition); return; }
private void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { SpawnBuilding(0); } if (Input.GetKeyDown(KeyCode.Alpha2)) { SpawnBuilding(1); } if (constructionState == ConstructionState.Positioning) { Tile tile = rayCast.GetNearestTileFromCursor(); if (tile != null) { selectedBuilding.Move(tile.tileCenter.transform.position); if (Input.GetMouseButtonDown(0)) { if (tile.tileState == Tile.TileState.Empty) { StartCoroutine(PlaceBuilding()); } else { messageLog.AddMessage("Tile is not empty", true); } } } } }