public void SetNextPurchaseCost(GameObject tower)
    {
        if (tower != null)
        {
            if (tower.GetComponent <TowerController>().GetTowerType() == "tower_fire")
            {
                nextUpgradeCost.text = CostTemplate.GetCost("tower_fire_2").ToString();
            }
            else if (tower.GetComponent <TowerController>().GetTowerType() == "tower_fire_2")
            {
                nextUpgradeCost.text = CostTemplate.GetCost("tower_fire_3").ToString();
            }
            else if (tower.GetComponent <TowerController>().GetTowerType() == "tower_ice")
            {
                nextUpgradeCost.text = CostTemplate.GetCost("tower_ice_2").ToString();
            }
            else if (tower.GetComponent <TowerController>().GetTowerType() == "tower_ice_2")
            {
                nextUpgradeCost.text = CostTemplate.GetCost("tower_ice_3").ToString();
            }

            else if (tower.GetComponent <TowerController>().GetTowerType() == "tower_nature")
            {
                nextUpgradeCost.text = CostTemplate.GetCost("tower_nature_2").ToString();
            }
            else if (tower.GetComponent <TowerController>().GetTowerType() == "tower_nature_2")
            {
                nextUpgradeCost.text = CostTemplate.GetCost("tower_nature_3").ToString();
            }
            else
            {
                nextUpgradeCost.text = "";
            }
        }
    }
    public void PlaceTower()
    {
        //Can a base tower be purchased
        //if true it buys it right away.
        //Checks if already purchased

        if (!towerSpawner.GetSpawnAble())
        {
            if (GameController.Purchase(CostTemplate.GetCost("tower_base")))
            {
                towerSpawner.SetSpawnable();
            }
            else
            {
                //GUI Status Text
                guiStatusText.text = "You don't have enough gold to purchase that.";
            }
        }
        else
        {
            guiStatusText.text = "A tower is already purchased and ready to be placed.";
        }
    }
    public void UpgradeFromBase(int type)
    {
        if (towerSelected != null)
        {
            Vector3 pos        = towerSelected.transform.position;
            NodeV2  parentNode = towerSelected.GetComponentInParent <NodeV2>();

            switch (type)
            {
            //Purchase Fire Towers
            case 0:
                if (GameController.Purchase(CostTemplate.GetCost("tower_fire")))
                {
                    parentNode.ReplaceTower();
                    GameObject newTower = Instantiate(towers["tower_fire"], pos, Quaternion.identity) as GameObject;
                    parentNode.SetTowerObject(newTower);
                    towerSelected             = newTower;
                    newTower.transform.parent = parentNode.transform;

                    SetNextPurchaseCost(towerSelected);


                    DeSpawnMenu();
                    towerSelected.GetComponent <Outline>().enabled = true;
                    selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                    SpawnMenu(towerSelected);
                }
                else
                {
                    guiStatusText.text = "Not enough money to upgrade to Fire";
                }
                break;

            //ice
            case 1:
                if (GameController.Purchase(CostTemplate.GetCost("tower_ice")))
                {
                    parentNode.ReplaceTower();
                    GameObject newTower = Instantiate(towers["tower_ice"], pos, Quaternion.identity) as GameObject;
                    towerSelected = newTower;
                    parentNode.SetTowerObject(newTower);
                    newTower.transform.parent = parentNode.transform;

                    SetNextPurchaseCost(towerSelected);

                    DeSpawnMenu();
                    towerSelected.GetComponent <Outline>().enabled = true;
                    selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                    SpawnMenu(towerSelected);
                }
                else
                {
                    guiStatusText.text = "Not enough money to upgrade to Ice";
                }
                break;

            //nature
            case 2:
                if (GameController.Purchase(CostTemplate.GetCost("tower_nature")))
                {
                    parentNode.ReplaceTower();
                    GameObject newTower = Instantiate(towers["tower_nature"], pos, Quaternion.identity) as GameObject;
                    towerSelected = newTower;
                    parentNode.SetTowerObject(newTower);
                    newTower.transform.parent = parentNode.transform;

                    SetNextPurchaseCost(towerSelected);


                    DeSpawnMenu();
                    towerSelected.GetComponent <Outline>().enabled = true;
                    selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                    SpawnMenu(towerSelected);
                }
                else
                {
                    guiStatusText.text = "Not enough money to upgrade to Nature";
                }
                break;

            case 3:
                SellTower(towerSelected, parentNode);
                DeSpawnMenu();
                break;
            }
        }
    }
    //Tower upgrades if an elemental tower already exists
    public void UpgradeFromElement(int type)
    {
        if (towerSelected != null)
        {
            Vector3 pos        = towerSelected.transform.position;
            NodeV2  parentNode = towerSelected.GetComponentInParent <NodeV2>();

            if (type == 0)
            {
                //
                //Fire Tower Upgrades
                //
                if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_fire")
                {
                    if (GameController.Purchase(CostTemplate.GetCost("tower_fire_2")))
                    {
                        parentNode.ReplaceTower();
                        GameObject newTower = Instantiate(towers["tower_fire_2"], pos, Quaternion.identity) as GameObject;
                        parentNode.SetTowerObject(newTower);
                        towerSelected             = newTower;
                        newTower.transform.parent = parentNode.transform;
                        towerSelected.GetComponent <Outline>().enabled = true;
                        nextUpgradeCost.text     = CostTemplate.GetCost("tower_fire_3").ToString();
                        selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                        SpawnMenu(towerSelected);
                    }
                    else
                    {
                        guiStatusText.text = "Not enough money to upgrade to Fire Tower 2";
                    }
                }
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_fire_2")
                {
                    if (GameController.Purchase(CostTemplate.GetCost("tower_fire_3")))
                    {
                        parentNode.ReplaceTower();
                        GameObject newTower = Instantiate(towers["tower_fire_3"], pos, Quaternion.identity) as GameObject;
                        parentNode.SetTowerObject(newTower);
                        towerSelected             = newTower;
                        newTower.transform.parent = parentNode.transform;

                        nextUpgradeCost.text = "";
                        towerSelected.GetComponent <Outline>().enabled = true;
                        selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;

                        SpawnMenu(towerSelected);
                    }
                    else
                    {
                        guiStatusText.text = "Not enough money to upgrade to Fire Tower 3";
                    }
                }
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_fire_3")
                {
                    guiStatusText.text = "Cannot upgrade Fire Tower any further.";
                }
                //
                //END FIRE UPGRADES
                //

                //
                //ICE TOWER UPGRADE
                //
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_ice")
                {
                    if (GameController.Purchase(CostTemplate.GetCost("tower_ice_2")))
                    {
                        parentNode.ReplaceTower();
                        GameObject newTower = Instantiate(towers["tower_ice_2"], pos, Quaternion.identity) as GameObject;
                        parentNode.SetTowerObject(newTower);
                        towerSelected             = newTower;
                        newTower.transform.parent = parentNode.transform;
                        //
                        //Component Testing Xav
                        //
                        towerSelected.GetComponent <Outline>().enabled = true;
                        nextUpgradeCost.text     = CostTemplate.GetCost("tower_ice_3").ToString();
                        selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                        SpawnMenu(towerSelected);
                        //
                        ///
                        //
                    }
                    else
                    {
                        guiStatusText.text = "Not enough money to upgrade to Ice Tower 2";
                    }
                }
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_ice_2")
                {
                    if (GameController.Purchase(CostTemplate.GetCost("tower_ice_3")))
                    {
                        parentNode.ReplaceTower();
                        GameObject newTower = Instantiate(towers["tower_ice_3"], pos, Quaternion.identity) as GameObject;
                        parentNode.SetTowerObject(newTower);
                        towerSelected             = newTower;
                        newTower.transform.parent = parentNode.transform;
                        //
                        //Component Testing Xav
                        //
                        towerSelected.GetComponent <Outline>().enabled = true;
                        nextUpgradeCost.text     = "";
                        selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                        SpawnMenu(towerSelected);
                        //
                        ///
                        //
                    }
                    else
                    {
                        guiStatusText.text = "Not enough money to upgrade to Ice Tower 3";
                    }
                }
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_ice_3")
                {
                    guiStatusText.text = "Cannot upgrade Ice Tower any further.";
                }
                //
                //END ICE UPGRADES
                //

                //
                //NATURE TOWER UPGRADES
                //
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_nature")
                {
                    if (GameController.Purchase(CostTemplate.GetCost("tower_nature_2")))
                    {
                        parentNode.ReplaceTower();
                        GameObject newTower = Instantiate(towers["tower_nature_2"], pos, Quaternion.identity) as GameObject;
                        parentNode.SetTowerObject(newTower);
                        towerSelected             = newTower;
                        newTower.transform.parent = parentNode.transform;
                        //
                        //Component Testing Xav
                        //
                        towerSelected.GetComponent <Outline>().enabled = true;
                        nextUpgradeCost.text     = CostTemplate.GetCost("tower_nature_3").ToString();
                        selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                        SpawnMenu(towerSelected);
                        //
                        ///
                        //
                    }
                    else
                    {
                        guiStatusText.text = "Not enough money to upgrade to Nature Tower 2";
                    }
                }
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_nature_2")
                {
                    if (GameController.Purchase(CostTemplate.GetCost("tower_nature_3")))
                    {
                        parentNode.ReplaceTower();
                        GameObject newTower = Instantiate(towers["tower_nature_3"], pos, Quaternion.identity) as GameObject;
                        parentNode.SetTowerObject(newTower);
                        towerSelected             = newTower;
                        newTower.transform.parent = parentNode.transform;
                        //
                        //Component Testing Xav
                        //
                        towerSelected.GetComponent <Outline>().enabled = true;
                        nextUpgradeCost.text     = "";
                        selectedTowerStatus.text = towerSelected.GetComponent <TowerController>().formattedName;
                        SpawnMenu(towerSelected);
                        //
                        ///
                        //
                    }
                    else
                    {
                        guiStatusText.text = "Not enough money to upgrade to Nature Tower 3";
                    }
                }
                else if (towerSelected.GetComponent <TowerController>().GetTowerType() == "tower_nature_3")
                {
                    guiStatusText.text = "Cannot upgrade Nature Tower any further.";
                }
                //
                //END NATURE UPGRADES
                //
            }
            else if (type == 1)
            {
                //downgrade
            }
            else if (type == 2)
            {
                //sell tower
                SellTower(towerSelected, parentNode);

                //
                //Component Testing
                //
                towerSelected = null;
                DeSpawnMenu();
                //
                //End Testing
                //
            }
        }
    }
    void ChangeTowerColor(Dropdown change, GameObject selected_tower)
    {
        if (change.value == 1)
        {
            //Before changing to fire check if there is enough money in wallet
            //Call tower right click menu script
            //Hard coding values now
            if (GameController.Purchase(CostTemplate.GetCost("tower_fire")))
            {
                ChangeTower(selected_tower, "fire");
            }
            else
            {
                guiStatusText.text = "Not enough money to upgrade to Fire";
            }
        }
        else if (change.value == 2)
        {
            if (GameController.Purchase(CostTemplate.GetCost("tower_ice")))
            {
                ChangeTower(selected_tower, "ice");
            }
            else
            {
                guiStatusText.text = "Not enough money to upgrade to Ice";
            }
        }
        else if (change.value == 3)
        {
            if (GameController.Purchase(CostTemplate.GetCost("tower_nature")))
            {
                ChangeTower(selected_tower, "nature");
            }
            else
            {
                guiStatusText.text = "Not enough money to upgrade to Nature";
            }
        }
        else if (change.value == 4)
        {
            //Sell Tower
            SellTower(selected_tower);
            guiStatusText.text = "Tower sold.";
        }
        else if (change.value == 5)
        {
            //Check if tower is a tower_base;

            if (selected_tower.GetComponent <TowerController>().CompareTag("Tower"))
            {
                guiStatusText.text = "Cannot downgrade base tower.";
            }
            else
            {
                GameController.SellTowerGetMoney(100);
                ChangeTower(selected_tower, "Base");
                guiStatusText.text = "Tower downgraded.";
            }
        }
        else
        {
            //Default action maybe?
        }
    }