Im having trouble resetting the score when i load my scene again with a button. i looked up for solutions but none for my game. The score just remains the same after the first game play. I’m also using the same scene.
Button script
public void reload()
{
SceneManager.LoadScene("Game");
}
Score script
Text score;
public static int bestScore;
public Text bestScoreText;
void Start ()
{
score = GetComponent<Text>();
bestScore = PlayerPrefs.GetInt("Best");
}
void Update ()
{
if (Enemy.Counter > bestScore)
{
bestScore = Enemy.Counter;
PlayerPrefs.GetInt("Best", bestScore);
}
score.text = "You Dodged " + Enemy.Counter;
bestScoreText.text = "Best " + bestScore;
}
Counter script
public static int Counter;
public static bool hitPlayer = false;
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Player")
{
hitPlayer = true;
}
if (col.gameObject.name == "Destroyer")
{
if (!hitPlayer)
Counter++;
Destroy(this.gameObject);
}