So i’m new to programming and writing scripts, and ive decided to make an incremental game just for fun and to learn new things. and i have come to a point where i think i should implement some kind of save system, before i add a bunch more stuff.
So i started using PlayerPrefs , and it works great for saving gold and other variables, but im having problems with saving how many upgrades i have bought. All my upgrades are in one script, and if i save Count , it thinks that every upgrade should have the same count.
Heres a pastebin http://pastebin.com/JspjPdDa , ignore the Playerprefs, i was just trying out different strategies. Thanks in advance.
No worries not sure what happened I submitted an answer yesterday. Anyways if you need different count values for different upgrades. You need to be able to differentiate your upgrades. Give your upgrades different ID values in PlayerPrefs, and associate that ID to a count value in PlayerPrefs.
Small example:
string upgradeID = 3;
int upgradeCount = 43;
PlayerPrefs.SetInt(upgradeID, upgradeCount);
This should guide you in the right path, you just need to make sure each time you generate a new upgrade, you give it a new ID somewhere in your script. When you are testing the logic, just print in a forloop all the available upgrades, and see if they have different count values.
Something like this:
string upgradeID = 3;
int upgradeCount = 43;
PlayerPrefs.SetInt(upgradeID, upgradeCount);
for (int i = 0; i < numberOfUpgrades; i++) {
print ("This is upgrade ID" + i + "its count value is " +
PlayerPrefs.GetInt(i.ToString()));
}