using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class ScoreKeeper : MonoBehaviour
{
    private TextMeshProUGUI ScoreThing;
    private int score;

    private static ScoreKeeper me;

    // Start is called before the first frame update
    void Awake()
    {
        DontDestroyOnLoad(this);
        me = this;
    }

    void Start()
    {
        ScoreThing = GameObject.FindGameObjectWithTag("ScoreBoard").GetComponent<TextMeshProUGUI>();
    }

    public void updateScore(int addToScore)
    {
        score += addToScore;
        updateScoreBoard();
    }

    private void updateScoreBoard()
    {
        ScoreThing.text = $"{score}";
    }

    public int getScore()
    {
        return score;
    }

    public static void maybeSetScore(int moreScore)
    {
        if (me != null)
        {
            me.updateScore(moreScore);
        }
    }
    
    public static int maybeGetScore()
    {
        if (me != null)
        {
           return me.getScore();
        }

        return 0;
    }

}
