using UnityEngine;
using TMPro;

public class ScoreBoard : MonoBehaviour
{
    public static ScoreBoard instance;
    
    [SerializeField] private TextMeshProUGUI scoreText;
    [SerializeField] private TextMeshProUGUI highScoreText;
    private int _score;
    
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
    }

    void Start()
    {
        scoreText.text = _score.ToString();
        highScoreText.text = PlayerPrefs.GetInt("HighScore", 0).ToString();
    }
    
    void UpdateHighScore()
    {
        if (_score > PlayerPrefs.GetInt("HighScore"))
        {
            PlayerPrefs.SetInt("HighScore", _score);
            highScoreText.text = _score.ToString();
        }
    }
    
    public void AddScore()
    {
        _score++;
        scoreText.text = _score.ToString();
        UpdateHighScore();
    }
    
}
