Example #1
0
    private void TryPlaceBuilding(Vector2Int pos)
    {
        bool isBuildingPlacable = true;

        foreach (Vector2Int occupyingLocation in currentTower.occupyingLocations)
        {
            if (Grid.GetCell(pos + occupyingLocation).occupied)
            {
                isBuildingPlacable = false;
            }
        }
        if (!isBuildingPlacable)
        {
            return;
        }
        else //if building is placable
        {
            foreach (Vector2Int occupyingLocation in currentTower.occupyingLocations)
            {
                Grid.GetCell(pos + occupyingLocation).occupied = true;
            }

            // Transfer control to a new tower
            foreach (var tower in new List <TowerBehavior>(GameManager.Instance.controlledTowers))
            {
                tower.LoseControl();
            }

            currentTower.Build();
            currentTower = null;
            LastUiAnimator.DeselectButton();
        }
    }