- Home /
Reset Score due to pressing button?
I have a c# script that keeps track of a score while playing the game and a 'retry' java script assigned to a button in the 'Game Over' Scene. How would I make the score reset due to the player pressing the retry button?
Answer by ltrout1999 · Apr 13, 2016 at 02:51 AM
You could just set the score back to zero. I'll write this in C# as I prefer C#, but you should get the gist. (also, this is pseudo-code)
public void OnClick()
{
playerScore = 0;
}
then just drag this script onto the button, go to the OnClick component in the button inspector window, drag the button onto the gameobject part and select the OnClick portion. Now when they click the button, the score will reset to 0. Hope this helps.
Answer by aditya · Apr 13, 2016 at 04:54 AM
Simply Re-Load the scene as this will reset everything to its original state....
using UnityEngine.SceneManagement;
SceneManager.LoadScene(YOUR SCENE NAME OR INDEX)