IEnumerator UpgradeFailedFeedback(UiUpgrade upgrade) { upgrade.failedMark.SetActive(true); yield return(new WaitForSecondsRealtime(.25f)); upgrade.failedMark.SetActive(false); }
void Upgrade(UiUpgrade upgrade) { //Upgrade GameMode gm = GameMode.instance; int price; if (gm.upgrades[upgrade.upgradeIndex].enabled) { price = gm.upgrades[upgrade.upgradeIndex].prices[gm.upgrades[upgrade.upgradeIndex].currentValueIndex + 1]; } else { price = gm.upgrades[upgrade.upgradeIndex].prices[gm.upgrades[upgrade.upgradeIndex].currentValueIndex]; } if (Player.instance.coins >= price) { Player.instance.coins -= price; GameMode.instance.upgrades[upgrade.upgradeIndex].Upgrade(); //this does the actual upgrade UpdateUiUpgrade(upgrade); UpdateUserInfoPanel(); Player.instance.StartCoroutine(Player.instance.Save()); //Save Player } else { UpdateUiUpgrade(upgrade, false); } }
void UpdateUiUpgrade(UiUpgrade upgrade, bool success = true) { if (!success) { StartCoroutine(UpgradeFailedFeedback(upgrade)); ShowNotificationPopup("Not enough Cash to upgrade!", Color.red); } UpgradeDetails upgradeDetails = GameMode.instance.upgrades[upgrade.upgradeIndex]; upgrade.nameField.text = upgradeDetails.name; if (upgradeDetails.enabled) { if (upgradeDetails.oneTime) { upgrade.priceField.text = upgradeDetails.prices[upgradeDetails.currentValueIndex].ToString(); } else { upgrade.priceField.text = upgradeDetails.prices[upgradeDetails.currentValueIndex + 1].ToString(); } if (upgradeDetails.oneTime) { //show completed upgrade.priceField.text = "Unlocked!"; upgrade.upgradeButton.onClick.RemoveAllListeners(); upgrade.upgradeButton.interactable = false; upgrade.completedMark.SetActive(true); } else { //show progress for (int i = 0; i <= upgradeDetails.currentValueIndex; i++) { upgrade.progressPanel.GetChild(i).GetComponent <Image>().color = Color.green; } if (upgradeDetails.currentValueIndex == upgradeDetails.values.Length - 1) { //show completed upgrade.priceField.text = "Unlocked!"; upgrade.upgradeButton.onClick.RemoveAllListeners(); upgrade.upgradeButton.interactable = false; upgrade.completedMark.SetActive(true); } } } else { upgrade.priceField.text = upgradeDetails.prices[upgradeDetails.currentValueIndex].ToString(); } }