/// <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(); }