Example #1
0
 private void SpawnIfAffordable(Vector2 roundedPosition)
 {
     if (defenderPrefab.GetMoneyCost() <= FindObjectOfType <MoneyDisplay>().GetActualMoney())
     {
         SpawnDefender(roundedPosition);
         FindObjectOfType <MoneyDisplay>().SpendMoney(defenderPrefab.GetMoneyCost());
     }
 }
    public void UpdateValues()
    {
        var textChildren = GetComponentsInChildren <TextMeshProUGUI>();

        textChildren[0].text = _defender.GetComponent <Health>().GetHealth.ToString();

        textChildren[4].text = _defender.GetPowerCost().ToString() + "P";
        textChildren[5].text = _defender.GetMoneyCost().ToString() + "M";

        var shooter = _defender.GetComponent <Shooter>();
        var plane   = _defender.isPlane;

        if (shooter)
        {
            textChildren[2].text = shooter.GetProjectileDamage().ToString();
        }
        else if (plane)
        {
            textChildren[0].text = "";
            textChildren[1].text = "";
            textChildren[2].text = _defender.GetComponent <Plane>().GetBombDamage.ToString();

            _movePrefab(textChildren[2]);
            _movePrefab(textChildren[3]);
        }
        else
        {
            textChildren[2].text = _defender.GetComponent <Exploder>().GetDamage.ToString();
        }
    }
Example #3
0
    private bool AttemptToPlaceDefender()
    {
        var currencyDisplay = FindObjectOfType <CurrencyController>();
        int powerCost       = _defender.GetPowerCost();
        int moneyCost       = _defender.GetMoneyCost();

        if (!currencyDisplay.HasEnoughCurrency(powerCost, moneyCost))
        {
            return(false);
        }

        currencyDisplay.SpendCurrency(powerCost, moneyCost);
        return(true);
    }
Example #4
0
    public void UpdateValues()
    {
        var textChildren = GetComponentsInChildren <TextMeshProUGUI>();

        if (_controlTower)
        {
            textChildren[0].text = _controlTower.GetHealth < 1 ? "--" : _controlTower.GetHealth.ToString();

            if (_controlTower.IsFixable)
            {
                textChildren[2].text = "";
                textChildren[3].text = "";
                textChildren[4].text = "";
                textChildren[5].text = "";

                textChildren[6].text = _controlTower.PowerCost.ToString() + "P";
                textChildren[7].text = _controlTower.MoneyCost.ToString() + "M";

                textChildren[8].text = "FIX";
            }
            else if (_controlTower.IsActive)
            {
                textChildren[2].text = "+" + _currencyController.GetControlTowerMoneyAffordance;
                textChildren[3].text = "POWER";
                textChildren[4].text = "+" + _currencyController.GetControlTowerPowerAffordance;
                textChildren[5].text = "MONEY";

                textChildren[6].text = "";
                textChildren[7].text = "";
                textChildren[8].text = "";
            }
            else     // dead
            {
                textChildren[2].text = "";
                textChildren[3].text = "";
                textChildren[4].text = "";
                textChildren[5].text = "";
                textChildren[6].text = "";
                textChildren[7].text = "";
                textChildren[8].text = "";
            }
        }
        else     // Currency Button
        {
            textChildren[0].text = _defender.GetComponent <Health>().GetHealth.ToString();

            var currencyProducer = FindObjectOfType <InfoController>().GetDefenderFromButton().GetComponent <CurrencyProducer>();

            // currency producer does not belong to button -- find boolean IsPower another way

            textChildren[2].text = currencyProducer.IsPower
                ? "+" + _currencyController.GetPowerAffordance
                : "+" + _currencyController.GetMoneyAffordance;
            textChildren[3].text = currencyProducer.IsPower ? "POWER" : "MONEY";

            // Second line of affordances
            textChildren[4].text = textChildren[5].text = "";

            textChildren[6].text = _defender.GetPowerCost() + "P";
            textChildren[7].text = _defender.GetMoneyCost() + "M";

            textChildren[8].text = "";
        }
    }