Working with settings
Saving data is always important, especially in games where you need to keep track of the player's progress or at the very least a track record of scores, plays, and other important data.
Within Unity, there is only one method of storing data natively, and that is PlayerPrefs
. It is very simple to use and very flexible, although it does have a hard limit of 1 MB of storage for the web player. It is possible to serialize data into PlayerPrefs
(and some developers do this), but generally if you need to serialize, most developers build their own system.
Using PlayerPrefs
PlayerPrefs
is simply a key dictionary to store individual variables as a key in the Unity runtime data store. On its own, it has to read each and every scene at runtime, which is why most games use a static class to keep the state stored in PlayerPrefs
and only use it between scenes for scene-specific configuration.
Using PlayerPrefs
is very easy and simple. The process is the same as any other dictionary...