예제 #1
0
    public void BuildSelectedTower(PlaceableTile tile)
    {
        var towerDataConfig = GetSelectedTowerDataConfig();

        if (towerDataConfig == null)
        {
            Debug.Log("TowerData not configured!  Skipping place tower.");
            return;
        }

        var tower = tile.PlaceTower(towerDataConfig.GetTowerPrefab());

        if (tower != null)
        {
            var towerComponent = tower.GetComponent <Tower>();
            towerComponent.SetTowerData(towerDataConfig.CreateTowerDataFromConfig());
        }
    }
예제 #2
0
    // Function first checks to see if ndoe has a tower on it.
    // If no tower is on  then it should check the player's money and decide if a tower should be built.
    // TODO: Either rename this function or Node.PlaceTower to prevent ambiguous names.
    public bool PlaceTower(GameObject tower, GameObject node)
    {
        if (Nodes[node].HasTower())
        {
            // Then the node already has a tower and cannot place another one.
            Debug.Log("This node already has a tower!");
            return(false);
        }
        else
        {
            // If not then place a tower using the Node.PlaceTower() function.
            GameObject newTower = (GameObject)Instantiate(tower, node.transform);
            // Add tower and associated node to Towers Dict
            PlaceableTile nodeScript = Nodes[node];
            nodeScript.PlaceTower(newTower);
            Towers.Add(nodeScript, newTower);

            // Set new tower as a child of the TowerManager GO for organization.
            newTower.transform.SetParent(transform, true);

            return(true);
        }
    }