i finally got player prefs to work, but unity insists that there is a problem, actually three. I made it so it saves the value of a variable, gold. it works, but it says a bunch of wierd problems. Heres the script with the gold variable:
and here's the script with the PlayerPrefs functions:
asked May 23 '10 at 04:22 AM
You do have several problems. For one, you're declaring the "gold" variable in Start, which makes it local to Start only, rather than global. Also you can't declare local variables as static, not that you want "gold" to be local anyway.
Also, you're doing PlayerPrefs.GetInt every frame in OnGUI, which is not a good idea at all. Just do it once when you need to load it, not every frame. Likewise, saving using PlayerPrefs every frame in Update is an even worse idea. Again, just do it once when needed.
Finally, your "saveIntPref" functions and so on don't really make any sense to me. Why not just use PlayerPrefs directly? I don't see what you're trying to gain by doing it that way.
answered May 23 '10 at 05:09 AM