Game Development Reference
In-Depth Information
PlayerPrefs.SetInt("PlayerRoundsLost",
pRoundsLost);
PlayerPrefs.SetFloat("PlayerKDR", pKDR);
PlayerPrefs.SetFloat("PlayerWLR", pWLR);
PlayerPrefs.SetFloat("PlayerTimePlayed",
pTimePlayed);
PlayerPrefs.Save();
}
This function is essentially the same as the ResetAllPrefs function, except we
change the value at which we assign PlayerPrefs . We assign all of the Player-
Prefs functions their appropriate stats, and then at the end of the function, we save
the PlayerPrefs values.
Setting a specific pref
To set a specific pref, we will create a function similar to how we set a specific stat.
Add this function to the script:
void SetPref(string Pref, int intValue = 0,
float fltValue = 0.00f)
{
if(intValue != 0)
{
if(PlayerPrefs.HasKey(Pref))
PlayerPrefs.SetInt(Pref, intValue);
}
if(fltValue != 0.00f)
{
if(PlayerPrefs.HasKey(Pref))
PlayerPrefs.SetFloat(Pref, fltValue);
}
PlayerPrefs.Save();
}
Search WWH ::




Custom Search