Restart HighScore

Hello, I have a question how reset highscore by button in C#. I don’t have idea how do it :confused:

I’m assuming you are saving the high score as an int? If so just reset it to 0 when the button is pressed

I think his problem is, that he don’t know, the button part. You can do:

C#:
void OnGUI () {
   if (GUI.Button(new Rect(10, 10, 100, 100), "Reset HighScore")     {
      HighScore = 0;
   }
}
JS:
function OnGUI () {
   if (GUI.Button(new Rect(10, 10, 100, 100), "Reset HighScore")     {
      HighScore = 0;
   }
}

Assuming you are saving your Highscore on Highscore.text
use PlayerPrefs.DeleteKey to reset only one item.
use PlayerPrefs.DeleteAll to reset everything… example player stats,levels unlocked etc

public void Reset()
{
PlayerPrefs.DeleteKey(“Highscore”);
}

or

public void Reset()
{
PlayerPrefs.DeleteAll(); // deletes all saved records
Highscore.text = “0”; // the number you want to reset your highscore to…
}

3 Likes

I tried this, but it automatically resets the highscore each time. I am trying to setup a button to reset the high score when clicked.

I must be doing something wrong. I put the script on canvas, added canvas to ‘OnClick’ section, and choose “Reset()” as the OnClick function, yet it seems to activate automatically. :slight_smile:

Learning Unity/C# - fun & annoying at the same time. lol

Please show your code.