public override bool DeleteBuilding() { bool test = base.DeleteBuilding(); if (test) { BuildingManager.buildingManager.alreadyPlacedDownBuildings.Remove(BuildingPanel.SubstringClonedBuilding(this.name)); BuildingPanel.buildingPanel.GeneratePanel(); } return(test); }
/** * Upgrades building to level 2 resource building */ public virtual bool UpgradeBuilding() { UpgradePanel.upgradePanel.gameObject.SetActive(false); Building upgrade = null; string newName = this.name.Replace("Lvl 1(Clone)", "Lvl 2"); foreach (Building b in PrefabManager.prefabManager.buildings) { if (b.name == newName) { upgrade = b; } } // If upgrade does not exist if (upgrade == null) { Debug.LogError(string.Format("{0} does not exist", newName)); Toast.toast.makeToast("Further upgrades do not exist"); return(false); } else { Tile temp = null; foreach (Tile t in TileScript.grid.tiles) { if (t.building != null && t.building.Equals(this)) { temp = t; } } Building upgraded = (Building)Instantiate(upgrade, new Vector3(temp.transform.position.x, temp.transform.position.y - .25f, 1), Quaternion.identity); upgraded.transform.parent = BuildingManager.buildingManager.Buildings.transform; SaveState.state.earth = SaveState.state.earth - this.earthCost; SaveState.state.water = SaveState.state.water - this.waterCost; SaveState.state.air = SaveState.state.air - this.airCost; SaveState.state.fire = SaveState.state.fire - this.fireCost; this.DeleteBuilding(); BuildingManager.buildingManager.alreadyPlacedDownBuildings.Add(BuildingPanel.SubstringClonedBuilding(upgraded.name)); BuildingPanel.buildingPanel.GeneratePanel(); return(true); } }