Game Development Reference
In-Depth Information
PlayerPrefs.SetInt("PlayerTotalGold", 0);
PlayerPrefs.SetInt("PlayerCurrentGold", 0);
PlayerPrefs.SetInt("PlayerGoldSpent", 0);
PlayerPrefs.SetInt("PlayerLevel", 0);
PlayerPrefs.SetInt("PlayerRoundsWon", 0);
PlayerPrefs.SetInt("PlayerRoundsLost", 0);
PlayerPrefs.SetFloat("PlayerKDR", 0.00f);
PlayerPrefs.SetFloat("PlayerWLR", 0.00f);
PlayerPrefs.SetFloat("PlayerTimePlayed",
0.00f);
PlayerPrefs.Save();
}
What this function does is set each
PlayerPref
value to its base value. When they
are all reset, we call a native
Save
function within
PlayerPrefs
to save our new
values.
Saving all of our prefs
The next function that we will create will allow us to save all of our
PlayerPrefs
values. This will be done in a similar way to how we reset all
PlayerPrefs
. Let's
add this new function now:
void SaveAllPrefs()
{
PlayerPrefs.SetInt("PlayerKills", pKills);
PlayerPrefs.SetInt("PlayerDeaths", pDeaths);
PlayerPrefs.SetInt("PlayerTotalGold",
pTotalGold);
PlayerPrefs.SetInt("PlayerCurrentGold",
pCurrentGold);
PlayerPrefs.SetInt("PlayerGoldSpent",
pGoldSpent);
PlayerPrefs.SetInt("PlayerLevel", pLevel);
PlayerPrefs.SetInt("PlayerRoundsWon",
pRoundsWon);