Example #1
0
    public void UpdateState(TowerViewModel viewModel)
    {
        if (viewModel.IsSold)
        {
            FlyingTextSpawner.SpawnGoldEarned(viewModel.SellPrice, gameObject);
            Destroy(gameObject);
            return;
        }

        if (ammoBar == null)
        {
            attacher = GetComponent <PrefabAttacher>();
            attacher.AttachPrefab();
            ammoBar = attacher.GetInstance().transform.Find("Ammunition Bar").GetComponent <Bar>();
            ammoBar.pointsImage
                = attacher.
                  GetInstance().
                  transform.Find("Ammunition Bar/Ammo").
                  GetComponent <Image>();
            disabler = GetComponent <ObjectDisabler>();
            GameObject buttons = ammoBar.gameObject.transform.parent.Find("Buttons").gameObject;
            disabler.toBeDisabled = buttons;
            disabler.Disable();

            reloadButton = buttons.transform.Find("Reload").GetComponent <Button>();
            sellButton   = buttons.transform.Find("Sell").GetComponent <Button>();

            reloadButton.onClick.AddListener(OnReload);
            sellButton.onClick.AddListener(OnSell);
        }

        range = viewModel.Range;
        ammoBar.UpdateState(viewModel.Ammo, viewModel.MaxAmmo);

        int ammoPercentage = (int)(viewModel.Ammo / viewModel.MaxAmmo * 100);

        if (ammoPercentage != lastAmmoPercentageShown)
        {
            lastAmmoPercentageShown = ammoPercentage;
            if (ammoPercentage < nextMilestone)
            {
                FlyingTextSpawner.SpawnAmmunitionLeft(ammoPercentage, gameObject);
                nextMilestone -= 100;
            }
        }

        if (viewModel.ReloadPrice != 0)
        {
            FlyingTextSpawner.SpawnGoldSpent(viewModel.ReloadPrice, gameObject);
        }
    }
Example #2
0
 void Start()
 {
     FlyingTextSpawner.SpawnGoldSpent((new RegularPriceList()).GetPrice(Controller.Model.Type), gameObject);
 }