/// <summary>Instantiates the clicked tower into the game somewhere.</summary> private void TowerClicked(GameObject prefab) { // Return if already purchasing to avoid nasty bugs :P if (selectedTowerForPurchase != null || bSelling) { return; } AudioHandler.ClickSound(); GameObject ins = Object.Instantiate(prefab, TowerManager.towersContainer); ins.GetComponent <RectTransform>().anchoredPosition = new Vector2(GameManager.CANVAS_WIDTH / 2.0f, GameManager.CANVAS_HEIGHT / -2.0f); ins.SetActive(true); selectedTowerForPurchase = ins.GetComponent <ITower>(); selectedCp = ins.GetComponent <TowerClickPoint>(); selectedCp.enabled = false; // Don't allow clicking for sell while purchasing. selectedTd = selectedTowerForPurchase.GetRangeCircle().AddComponent <TowerDisplay>(); // To allow dragging. selectedTd.Initialise(); selectedTowerForPurchase.ShowRangeCircle(true); selectedTowerForPurchase.SetEnabled(false); // Show the buy options buyOptions.alpha = 1.0f; buyOptions.gameObject.SetActive(true); label_selectedInfoHeader.text = selectedTowerForPurchase.MyInfo().towerName; label_selectedInfoContent.text = selectedTowerForPurchase.MyInfo().towerDescription; bBuying = true; }
private void TowerPurchaseConfirm() { // Return if it's on the path. if (!selectedTd.validPosition) { return; } AudioHandler.ClickSound(); //Debug.Log(selectedTowerForPurchase.GetGameobject().name); selectedTowerForPurchase.ShowRangeCircle(false); selectedTowerForPurchase.SetEnabled(true); selectedTowerForPurchase.LockMovement(); selectedCp.enabled = true; // Remove the cost from the health (needs to be down here) healthFlag = true; Player.health -= selectedTowerForPurchase.MyInfo().cost; healthFlag = false; HideBuyOptions(); }
private void HideSellOptions() { selectedTowerForSell.ShowRangeCircle(false); selectedTowerForSell = null; sellOptions.alpha = 0.0f; sellOptions.gameObject.SetActive(false); bSelling = false; }
/// <summary>Shows the sell options for the selected tower.</summary> public void OwnedTowerClick(ITower click) { if (bBuying) { return; } selectedTowerForSell = click; selectedTowerForSell.ShowRangeCircle(true); label_sellBtn.text = string.Format("{0}{1:n0}", TEXT_SELLBTN, selectedTowerForSell.SellPrice()); sellOptions.alpha = 1.0f; sellOptions.gameObject.SetActive(true); bSelling = true; }