PlayerPrefs
utility is use to store data permanently till the app installed on device. And types supported to store is limited, such as float
, int
, string
. You can further use it, derive new methods using int
and string
, its up to you.
PlayerPrefs
uses Key-Value
structure, that means it will store a value (int, float, string) against a string
key. For example I'd save high score against the key "highscore"
, and by the same string
key I'd get back the stored value.
Now, to save score you can use
// To set high score
int scoreToSet = 140;
PlayerPrefs.SetInt("highscore", scoreToSet);
// To get high score
int scoreToGet = 0;
scoreToGet = PlayerPrefs.GetInt("highscore");
where "highscore"
is the string
key. Key must match in order to get and set values.