Game Development Reference
In-Depth Information
Resetting the stats
To reset our stats, we will add a basic but important function to our script, shown as
follows:
void ResetStats()
{
pKills = 0;
pDeaths = 0;
pTotalGold = 0;
pCurrentGold = 0;
pGoldSpent = 0;
pLevel = 1;
pRoundsWon = 0;
pRoundsLost = 0;
pKDR = 0.00f;
pWLR = 0.00f;
pTimePlayed = 0.00f;
}
When this function is called, it will reset all of our stats to their base value. This value
is 0 for everything but the player's level, which is 1 . If we wanted to reset a specif-
ic stat to its base value, we can call the previous function that we created, which is
SetStat .
Resetting all of our prefs
To save our stats, we will use Unity's PlayerPrefs . These are a handy way to save
small bits of data. They can be used across several platforms and are easy to use.
Our first function that we'll create will let us reset our PlayerPrefs value. Add this
function to the script:
void ResetAllPrefs()
{
PlayerPrefs.SetInt("PlayerKills", 0);
PlayerPrefs.SetInt("PlayerDeaths", 0);
Search WWH ::




Custom Search