public static void PreBuildTower(UnitTower tower) { PlatformTD platform = null; LayerMask mask = 1 << LayerManager.LayerPlatform(); Collider[] cols = Physics.OverlapSphere(tower.thisT.position, _gridSize, mask); if (cols.Length > 0) { platform = cols[0].gameObject.GetComponent <PlatformTD>(); } if (platform != null) { Vector3 buildPos = GetTilePos(platform.thisT, tower.thisT.position); tower.thisT.position = buildPos; tower.thisT.rotation = platform.thisT.rotation; platform.BuildTower(buildPos, tower); } else { Debug.Log("no platform found for pre-placed tower"); } tower.InitTower(instance.towerCount += 1); if (tower.GetType() == typeof(UnitDefender)) { if (((UnitDefender)tower).behaviour == Behaviour.Stational) { tower.transform.Rotate(Vector3.up, 90); } } }
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"); }