// TODO: Pull the ui updating methods out of here // This is assigned to the button through the inspector! public void PurchaseTheUpgrade() { if (myUpgrade.priceOfNextUpgradeLvl < myMiningController.currentBalance && myUpgrade.currentUpgradeLvl < myUpgrade.maxUpgradeLvl) { // Charging for the upgrade myMiningController.currentBalance -= myUpgrade.priceOfNextUpgradeLvl; // Calculate the growth of the upgrade price myUpgrade.priceOfNextUpgradeLvl = CalculatePriceOfNextBuilding(myUpgrade.defPrOfNxtUpgLvl, myUpgrade.costBase, myUpgrade.currentUpgradeLvl); myUpgrade.currentUpgradeLvl++; // APPLYING THE UPGRADE EFFECTS HERE ApplyMyEffectsToGame(myUpgrade.myApplications, myUpgrade.buildingsISpawn); upgradeLevelUI.fillAmount = myUpgrade.currentUpgradeLvl / myUpgrade.maxUpgradeLvl; // IF THIS UPGRADE ONLY BUILDS STUFF... if (myUpgrade.myApplications.Count <= 0) { // Updating the text for the current and next effect if this is a building only upgrade currentEffectText.text = myUpgrade.currentUpgradeLvl.ToString(); miscTextField.text = myUpgrade.miscText + " " + myUpgrade.maxUpgradeLvl; } else { // ...IF THIS UPGRADE ALSO AFFECTS ATTRIBUTES // If this has been the last upgrade then turn the button off and make it gray if (myUpgrade.currentUpgradeLvl == myUpgrade.maxUpgradeLvl) { miscTextField.text = myUpgrade.GenerateNextUpgradeTextAnnouncement(); upgradeButton.interactable = false; buttonText.text = "MAX UPGRADE PURCHASED"; //Debug.Log("Turnt off the " + myUpgrade.title + " button"); upgradeButton.GetComponent <Image>().color = Color.gray; return; } currentEffectText.text = myUpgrade.GenerateCurrentEffectTextAnnouncement(); miscTextField.text = myUpgrade.GenerateNextUpgradeTextAnnouncement(); } // Check if after applying this upgrade we've reached the maximum one if (myUpgrade.currentUpgradeLvl == myUpgrade.maxUpgradeLvl) { // Turn off the button if we reached max upgrade upgradeButton.interactable = false; upgradeButton.GetComponent <Image>().color = Color.gray; return; } // Update the text on the button to display the price of the next step buttonText.text = "BUY" + "\n" + NumberConverter.ConvertNumber(myUpgrade.priceOfNextUpgradeLvl); } else { Debug.Log("Not enough money for this upgrade right now!"); return; } }
// Update is called once per frame void Update() { balanceText.text = NumberConverter.ConvertNumber(myMiningController.currentBalance); perSecondText.text = NumberConverter.ConvertNumber(myMiningController.coinsPerSec) + "/s"; }