Files
2026-05-04 22:36:24 +03:00

72 lines
1.7 KiB
C#

using System.Collections.Generic;
using Code.UI;
using TMPro;
using UnityEngine;
namespace Code.GameplayServices
{
public class PlayerScoreService : MonoBehaviour
{
[SerializeField] private ScoreTable scoreTable;
public void ShowScoreTable()
{
scoreTable.gameObject.SetActive(true);
}
[SerializeField] private TMP_Text scoreText;
[SerializeField] private TMP_Text playerNameText;
private List<ScoreData> _scores = new();
public List<ScoreData> Scores => _scores;
private int _score;
private string _playerName;
public static PlayerScoreService Instance { get; private set; }
public int Score => _score;
private void Awake()
{
Instance = this;
}
public void AddScore(int score)
{
_score += BonusService.Instance.CoinBoost ? score * 2 : score;
UpdateScoreTextWithScoreValue();
}
private void UpdateScoreTextWithScoreValue()
{
scoreText.text = _score.ToString();
}
public void ResetScore()
{
_scores.Add(new ScoreData(_playerName, _score));
_score = 0;
// _playerName = string.Empty;
scoreText.text = _score.ToString();
}
public void SetPlayerName(string playerName)
{
_playerName = playerName;
playerNameText.text = _playerName;
}
}
public struct ScoreData
{
public string name;
public int score;
public ScoreData(string name, int score)
{
this.name = name;
this.score = score;
}
}
}