Hello, I have a question how reset highscore by button in C#. I don’t have idea how do it ![]()
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…
}
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. ![]()
Learning Unity/C# - fun & annoying at the same time. lol
Please show your code.