public string UpgradeToNextTower(int ID = 0) { UnitTower nextLevelTower = nextLevelTowerList[Mathf.Clamp(ID, 0, nextLevelTowerList.Count)]; List <int> cost = GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { ResourceManager.SpendResource(cost); GameObject towerObj = (GameObject)ObjectPoolManager.Spawn(nextLevelTower.gameObject, thisT.position, thisT.rotation); UnitTower towerInstance = towerObj.GetComponent <UnitTower>(); towerInstance.InitTower(instanceID); towerInstance.SetPlatform(occupiedPlatform, occupiedNode); towerInstance.AddValue(value); towerInstance.SetLevel(level + 1); towerInstance.Build(); GameControl.SelectTower(towerInstance); if (onUpgradedE != null) { onUpgradedE(towerInstance); } ObjectPoolManager.Unspawn(thisObj); return(""); } return("Insufficient Resource"); }
//called by any external component to build tower, uses buildInfo public static string BuildTower(UnitTower tower) { if (buildInfo == null) { return("Select a Build Point First"); } //dont allow building of resource tower before game started if (tower.type == _TowerType.Resource && !GameControl.IsGameStarted()) { return("Cant Build Tower before spawn start"); } UnitTower sampleTower = GetSampleTower(tower); //check if there are sufficient resource List <int> cost = sampleTower.GetCost(); int suffCost = ResourceManager.HasSufficientResource(cost); if (suffCost == -1) { ResourceManager.SpendResource(cost); GameObject towerObj = (GameObject)ObjectPoolManager.Spawn(tower.gameObject, buildInfo.position, buildInfo.platform.thisT.rotation); UnitTower towerInstance = towerObj.GetComponent <UnitTower>(); towerInstance.InitTower(instance.towerCount += 1); towerInstance.Build(); //register the tower to the platform if (buildInfo.platform != null) { buildInfo.platform.BuildTower(buildInfo.position, towerInstance); } //clear the build info and indicator for build manager ClearBuildPoint(); return(""); } return("Insufficient Resource"); }