37 lines
793 B
C#
37 lines
793 B
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace Code.GameplayServices
|
|
{
|
|
public class PlayerScoreService : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text scoreText;
|
|
|
|
private int _score;
|
|
|
|
public static PlayerScoreService Instance { get; private set; }
|
|
public int Score => _score;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void AddScore(int score)
|
|
{
|
|
_score += score;
|
|
UpdateScoreTextWithScoreValue();
|
|
}
|
|
|
|
private void UpdateScoreTextWithScoreValue()
|
|
{
|
|
scoreText.text = _score.ToString();
|
|
}
|
|
|
|
public void ResetScore()
|
|
{
|
|
_score = 0;
|
|
scoreText.text = _score.ToString();
|
|
}
|
|
}
|
|
} |