-
-
Notifications
You must be signed in to change notification settings - Fork 30
Home
Adam Graham edited this page Nov 13, 2023
·
6 revisions
Yes, you are free to use the project for any purpose. However, keep in mind that copyright and/or trademark laws can still apply to the original material since many of the games in my tutorials were not originally authored by me. I open source my own code for the community to learn from, but the project is intended for educational purposes only.
Using Unity's PlayerPrefs
is an easy way to save a hiscore to the local system. When we update the score in the GameManager.cs
script, we can also update the hiscore if its been beaten:
public void IncreaseScore(int points)
{
score += points;
scoreText.text = score.ToString();
float hiscore = PlayerPrefs.GetFloat("hiscore", 0);
if (score > hiscore)
{
hiscore = score;
PlayerPrefs.SetFloat("hiscore", hiscore);
}
}