This is my Score script
public class score1 : MonoBehaviour
{
public static score1 instance;
private Text scoreText;
public int scr;
void Start()
{
scr = 0;
}
// Start is called before the first frame update
void Awake()
{
scoreText = GameObject.Find("scores").GetComponent<Text>();
MakeInstance();
}
// Update is called once per frame
void MakeInstance()
{
if (instance == null)
instance = this;
}
public void IncrementScore()
{
scr++;
scoreText.text = "Score:" + scr;
}
public int GetScore()
{
return this.scr;
}
}
And this is the code which calls the increment if this is needed
if (transform.localScale.x <= 0.4f && score1.instance != null)
{
score1.instance.IncrementScore();
PlayerPrefs.SetInt("Score", score1.instance.GetScore());
}
if (transform.localScale.x <= 0.05f)
{
Destroy(gameObject);
}
and if game is over at 0 its reading the previous score instead of 0