Exemplo n.º 1
0
    /// <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;
    }