Game Development Reference
In-Depth Information
break;
case "RoundsLost":
PlayerPrefs.SetInt("PlayerRoundsLost", 0);
break;
case "KDR":
PlayerPrefs.SetFloat("PlayerKDR", 0.00f);
break;
case "WLR":
PlayerPrefs.SetFloat("PlayerWLR", 0.00f);
break;
case "TimePlayed":
PlayerPrefs.SetFloat("PlayerTimePlayed",
0.00f);
break;
}
PlayerPrefs.Save();
}
For this function, we pass one variable that we want to reset, which is
PlayerPref
.
Then, we run a
switch
statement for the string that we passed to decide which
PlayerPref
function to reset. After we reset
PlayerPref
, we save it.
Showing our stats on the screen
Our final step in creating our stats is to show them on the screen. To do this, we will
need to first add a couple of more variables:
public bool showStats = false;
public Rect statsRect = new Rect(Screen.width /
2, Screen.height / 2, 400, 400);
The new
bool
variable will decide whether we can show the stats menu, and the
Rect
variable is the area in which the stats menu will be. Next, we will add the
OnGUI
function that will draw our GUI on the screen: