public void UpgradeTurret() { //check if the player has enough money to upgrade. otherwise nothing happens and an error message happens. if (PlayerStats.money < turret_blueprint.upgrade_cost) { return; } //check if the tower is already upgraded. if (!is_upgraded) { //otherwise, remove their old tower and money. then build them the upgraded tower. Destroy(tower); PlayerStats.money -= turret_blueprint.upgrade_cost; GameObject _tower = (GameObject)Instantiate(turret_blueprint.upgraded_prefab, GetBuildPosition(), Quaternion.identity); _tower.transform.parent = GameObject.Find("BuildList").transform; tower = _tower; click_scr = tower.GetComponent <ClickTower>(); click_scr.pass_spots(this); for (int i = 0; i < times_rotated; i++) { UpgradeRotation(); } is_upgraded = true; } }
public void SellTurret() { //adds money to the player's stats PlayerStats.money += turret_blueprint.GetSellAmount(); //destroy the tower and reset the upgraded boolean to allow for upgrading again Destroy(tower); is_upgraded = false; //sets the blueprint to null because there is no current tower on this spot. turret_blueprint = null; click_scr = null; PlayerStats.building_amount--; if (PlayerStats.building_amount < 0) { PlayerStats.building_amount = 0; } }
void BuildTurret(TurretBlueprint _blueprint) { //check if the player has enough money to build. otherwise nothing happens and an error message happens. if (PlayerStats.money < _blueprint.cost || PlayerStats.building_amount >= PlayerStats.building_limit) { //Debug.Log("Not enough money to build."); return; } //otherwise, remove their money from the cost and build them the tower. Destroy(previewed_tower); PlayerStats.money -= _blueprint.cost; GameObject _tower = (GameObject)Instantiate(_blueprint.prefab, GetBuildPosition(), Quaternion.identity); _tower.transform.parent = GameObject.Find("BuildList").transform; tower = _tower; click_scr = tower.GetComponent <ClickTower>(); click_scr.pass_spots(this); turret_blueprint = _blueprint; PlayerStats.building_amount++; }