public void PurchaseTower(TowerPlatform _platform) { Player.instance.PurchaseTower(towerToPurchase); Tower newTower = Instantiate(towerToPurchase); _platform.AddTower(newTower); aliveTowers.Add(newTower); }
private void InstantiateNewTower(TowerPlatform towerPlatform) { Tower placedTower = Instantiate(tower, towerPlatform.transform.position, Quaternion.identity, parent); placedTower.builtOnPlatform = towerPlatform; towerPlatform.TogglePlaceable(); towers.Enqueue(placedTower); }
private void OnTriggerEnter(Collider other) { currentTowerPlatform = other.GetComponentInParent <TowerPlatform>(); towerExists = other.GetComponentInChildren <TowerCheck>(); currentTower = other.GetComponentInChildren <TowerCheck>(); if (other.GetComponentInChildren <TowerType>()) { upgradePriceText.text = "$" + other.GetComponentInChildren <TowerType>().upgradeCost; } towerManager.SetupTowerPrices(); }
public void AddTower(TowerPlatform towerPlatform) { if (towers.Count < towerLimit) { InstantiateNewTower(towerPlatform); print(towers.Count + " tower(s) in scene"); } else { MoveExistingTower(towerPlatform); } }
//De activates the radial menu object. void DisableRadialMenu() { StartCoroutine(RadialMenuCloseAnimation()); if (selectedTowerPlatform != null) { //selectedTowerPlatform.transform.FindChild("Model").GetComponent<MeshRenderer>().material.color = Color.white; } selectedTower = null; selectedTowerPlatform = null; }
//Enables the tower platform radial menu. void SetRadialMenu(Vector2 posOnScreen, TowerPlatform towerPlatform) { towerPlatformMenu.SetActive(true); StartCoroutine(RadialMenuOpenAnimation()); SetTowerPlatformMenuButtons(towerPlatform); selectedTowerPlatform = towerPlatform; //Set the radial menu position to the same as the touch position on screen. transform.localPosition = new Vector3(posOnScreen.x - (Screen.width / 2), posOnScreen.y - (Screen.height / 2), 0); //towerPlatform.transform.FindChild("Model").GetComponent<MeshRenderer>().material.color = Color.green; FixRadialMenuPosition(); }
public void enableBuildUI(GameObject towerPlatform) { selectedTowerPlatform = towerPlatform.GetComponent <TowerPlatform>(); towerPos = towerPlatform.transform.position; transform.GetChild(0).gameObject.SetActive(true); Vector3 viewPos = mainCamera.WorldToViewportPoint(towerPos); if (viewPos.x >= 0.5f) { buildUI.rectTransform.anchoredPosition = new Vector2(180, 0); } else { buildUI.rectTransform.anchoredPosition = new Vector2(620, 0); } }
public bool PurchaseTower(TowerPlatform _platform, TowerTypes _towerType) { // true - if enough money, false - if not enough money bool towerWasBought = Player.instance.PurchaseTower(towers[_towerType]); if (towerWasBought) { Tower newTower = Instantiate(towers[_towerType]); _platform.AddTower(newTower); return(true); } else { return(false); } }
private void MoveExistingTower(TowerPlatform newPlatform) { // take the bottom tower off the queue Tower towerBeingMoved = towers.Dequeue(); // set old platform as placeable towerBeingMoved.builtOnPlatform.TogglePlaceable(); // set the new platform position towerBeingMoved.transform.position = newPlatform.transform.position; // set tower's new platform towerBeingMoved.builtOnPlatform = newPlatform; // set new platform as not placeable newPlatform.TogglePlaceable(); // add the tower on top of the queue towers.Enqueue(towerBeingMoved); }
//Sets the tower platform buttons to disable when pressed. //Sets the tower platform buttons to build a tower on the platform when pressed. void SetTowerPlatformMenuButtons(TowerPlatform towerPlatform) { foreach (Button button in towerPlatformMenuButtons) { button.onClick.RemoveAllListeners(); } towerPlatformMenuButtons[0].onClick.AddListener(() => towerPlatform.BuildTower(TowerType.RobotArm)); towerPlatformMenuButtons[1].onClick.AddListener(() => towerPlatform.BuildTower(TowerType.Crusher)); towerPlatformMenuButtons[2].onClick.AddListener(() => towerPlatform.BuildTower(TowerType.Lazer)); towerPlatformMenuButtons[3].onClick.AddListener(() => towerPlatform.BuildTower(TowerType.AcidEtcher)); towerPlatformMenuButtons[4].onClick.AddListener(() => towerPlatform.BuildTower(TowerType.Drill)); foreach (Button button in towerPlatformMenuButtons) { button.onClick.AddListener(DisableRadialMenu); } }