using UnityEngine;
using UnityEngine.UI;

public class ScoreManager : MonoBehaviour
{
    [SerializeField] private float currentScore;
    [SerializeField] private float amount = 10f;
    [SerializeField] private Text currentScoreText;
    [SerializeField] private Text highScoreText;

    private void Start()
    {
        currentScore = 0f;
        highScoreText.text = PlayerPrefs.GetFloat("HIGHSCORE", 0f).ToString("0");
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            DeleteHighScore();
        }

        if (GameManager.instance.isGameActive == false) {
            return;
        }
        currentScore += amount * Time.deltaTime;
        currentScoreText.text = currentScore.ToString("0");

        if (currentScore > PlayerPrefs.GetFloat("HIGHSCORE")) {
            PlayerPrefs.SetFloat("HIGHSCORE", currentScore);
            highScoreText.text = currentScore.ToString("0");
        }
    }

    void DeleteHighScore() {
        PlayerPrefs.DeleteKey("HIGHSCORE");
        highScoreText.text = "0";
    }
}
