Saving count with 1 script on multiple objects, am i doing it wrong?

i am a beginner with unity/C# but have learned quite a bit the last 3 days but i keep running in 1 thing i can save my money but not the count of how many items i bought this is in a incremental game can someone help me

i use PlayerPrefs to save, and this is the code i use to controll my upgrades


as you can see i already tried it this way but it didnt work and i disabled it in case it could interfere with something else am i doing something wrong?

I don’t see why it doesn’t work. Maybe it works but you never increase the count?

When is PurchaseUpgarade() called?

You should write something to the log when purchasing successfully.

Also, it is a bad idea to save the count every frame. Instead you should save it after you actually changed it.

PurchasedUpgrade() is called when i press the button
this is it with the save enabled

hmm… if update would be called before awake you would save the default value (zer0) before loading it. However this should not happen.

anyway: move the SetInt() call into the PurchaseUpgrade() method. Maybe that works better.

if it doesn’t work: check if you set the count variable from anywhere else in the code.

that worked thx for the tip. realy appriciated