Hello! I’ve been working on a game recently and wanted to add a function that would make an object active after a specific upgrade is purchased and make it stay active forever after the upgrade is obtained (unless the player resets his/her progress).
I tried approaching it like this:
The script on the upgrade button gets the amount of times it has been bought and stores it in a PlayerPref Int.
void Update () {
PlayerPrefs.SetInt ("itemcount",item.count);
}
The code on the object that becomes active checks if the item count is equal or above 1 ( so the upgrade was purchased) and makes the gameObject active if it’s true.
void Update () {
if (PlayerPrefs.GetInt("itemcount") >= 1)
{
gameObject.SetActive(true);
}
else
{
gameObject.SetActive(false);
}
}
}
The problem here is that the code works, but the game object will appear only after you restart the scene/game. I want it to appear right after you purchase the upgrade, how do I fix my code? Thanks it advance!