Game Development Reference
In-Depth Information
This function will take the
PlayerPref
function we want to set and also a value that
we want to set it to. Inside the function, we will check to see which value is not set to
0
. If one of the values are still
0
, we ignore that value type. If one of the values is not
0
, we check to see whether the
PlayerPref
function passed to the function exists.
If that function exists, we then set the
PlayerPref
value accordingly and finish off
by saving our
PlayerPrefs
values.
Resetting a specific pref
What if you wanted to reset a specific PlayerPref value? For this, we will create a
slightly different function that will allow us to do that. Add this new function to our
script:
void ResetPref(string Pref)
{
switch(Pref)
{
case "Kills":
PlayerPrefs.SetInt("PlayerKills", 0);
break;
case "Deaths":
PlayerPrefs.SetInt("PlayerDeaths", 0);
break;
case "TotalGold":
PlayerPrefs.SetInt("PlayerTotalGold", 0);
break;
case "CurrentGold":
PlayerPrefs.SetInt("PlayerCurrentGold", 0);
break;
case "GoldSpent":
PlayerPrefs.SetInt("PlayerGoldSpent", 0);
break;
case "Level":
PlayerPrefs.SetInt("PlayerLevel", 0);
break;
case "RoundsWon":
PlayerPrefs.SetInt("PlayerRoundsWon", 0);