using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerScore : MonoBehaviour
{
    [SerializeField] private Text scoreText;
    [SerializeField] private Text highScoreText;

    private int score;
    private int highscore;
    private float counter;

    // Start is called before the first frame update
    void Start()
    {
        highscore = PlayerPrefs.GetInt("highscore", 0);
        highScoreText.text = $"High Score: {highscore}";
        
        scoreText.text = $"Score: {score}";
    }

    // Update is called once per frame
    void Update()
    {
        counter += Time.deltaTime;
        if (counter >= 1)
        {
            score++;
            counter = 0;
            scoreText.text = $"Score: {score}";
        }
    }

    public void UpdateHighScore()
    {
        Debug.Log(highscore);
        Debug.Log(score);
        if (score > highscore)
        {
            highscore = score;
            PlayerPrefs.SetInt("highscore", highscore);
        }
    }
}
