public void UpdateUI() { wave.text = "Wave :\n" + Gamecontroller.instance.wave; points.text = "Points :\n" + Gamecontroller.instance.points; Defender selectedDefender = Gamecontroller.instance.SelectedDefender(); DefenderStats newDefender = null; if (selectedDefender != null) { newDefender = selectedDefender.stats; leftArrow.SetActive(false); rightArrow.SetActive(false); damageUpgrade.transform.parent.gameObject.SetActive(newDefender.DamageAfterUpgrade() != newDefender.damage); fireRateUpgrade.transform.parent.gameObject.SetActive(newDefender.FireRateAfterUpgrade() != newDefender.fireRate); rangeUpgrade.transform.parent.gameObject.SetActive(newDefender.RangeAfterUpgrade() != newDefender.range); priceText.text = "Sell:\n" + selectedDefender.stats.price; } else { leftArrow.SetActive(true); rightArrow.SetActive(true); damageUpgrade.transform.parent.gameObject.SetActive(false); fireRateUpgrade.transform.parent.gameObject.SetActive(false); rangeUpgrade.transform.parent.gameObject.SetActive(false); newDefender = Gamecontroller.instance.defenders[newDefenderIndex]; priceText.text = "buy:\n" + newDefender.price; } defenderName.text = newDefender.name; defenderImage.sprite = UiManager.instance.defendersImg[newDefender.image]; float currentDamage = Percentage(Gamecontroller.instance.maxDamage, newDefender.damage); float nextDamage = Percentage(Gamecontroller.instance.maxDamage, newDefender.DamageAfterUpgrade()); damageSlider.fillAmount = currentDamage; damageSlider.transform.GetChild(0).GetComponent <Image>().fillAmount = nextDamage; damageUpgrade.text = "+ " + newDefender.upgradePrice; float currentFireRate = Percentage(Gamecontroller.instance.maxFireRate, newDefender.fireRate); float nextFireRate = Percentage(Gamecontroller.instance.maxFireRate, newDefender.FireRateAfterUpgrade()); fireRateSlider.fillAmount = currentFireRate; fireRateSlider.transform.GetChild(0).GetComponent <Image>().fillAmount = nextFireRate; fireRateUpgrade.text = "+ " + newDefender.upgradePrice; float currentRange = Percentage(Gamecontroller.instance.maxRange, newDefender.range); float nextFireRange = Percentage(Gamecontroller.instance.maxRange, newDefender.RangeAfterUpgrade()); rangeSlider.fillAmount = currentRange; rangeSlider.transform.GetChild(0).GetComponent <Image>().fillAmount = nextFireRange; rangeUpgrade.text = "+ " + newDefender.upgradePrice; }
public void UpgradeDamage() { DefenderStats defender = SelectedDefender().stats; if (defender.upgradePrice <= points) { points -= defender.upgradePrice; defender.damage = defender.DamageAfterUpgrade(); } UiManager.instance.UpdateUI(); }