So I save data from a scene to another but when I start again the game I still have the score that I gain after playing . I am at the first scene and my score is 4 instead of 0 . How can I get my score at new game = 0 ? here is my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScorePanelUpdater : MonoBehaviour
{
//Start is called before the first frame update
void Update()
{
GameObject go = GameObject.Find("Score");
if(go == null)
{
Debug.LogError("Failed");
this.enabled = false;
return;
}
Score gs = go.GetComponent<Score>();
GetComponent<Text>().text = " Score: " + gs.GetScore();
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public Text scoreText;
public int score;
public Button button;
// Use this for initialization
void Start()
{
score = PlayerPrefs.GetInt("score", 0);
Button btn = GetComponent<Button>();
button.onClick.AddListener(TaskOnClick);
}
void Update()
{
scoreText.text = "Score: " + score;
}
void OnDestroy()
{
PlayerPrefs.SetInt("score", score);
}
public void AddScore(int s)
{
score += s;
}
public int GetScore()
{
return score;
}
// Update is called once per frame
void TaskOnClick()
{
score++;
}
}