playerprefs unity bol code example
Example: playerprefs unity
//Variables of different type
int number = 18;
float decimal = 1.84f;
string word = "Jeff";
//Setting each PlayerPref to a Variable, with .Set and the type of Variable its set too (.SetFloat)
PlayerPrefs.SetInt("Age", number);
PlayerPrefs.SetFloat("Height", decimal);
PlayerPrefs.SetString("Name", word);
//Displaying the PlayerPref in Console, with .Get and its type of data (.GetString)
Debug.Log(PlayerPrefs.GetInt("Age"));
Debug.Log(PlayerPrefs.GetFloat("Height", 1.5));// Adding a default Value incase the PlayerPref isn't storing any data
Debug.Log(PlayerPrefs.GetString("Name"));
/*Desplayed in Console:
18
1.84
Jeff
*/
//Reseting data in one PlayerPref
PlayerPrefs.DeleteKey("Height");
//Reseting data in all PlayerPrefs
P layerPrefs.DeleteAll();