using System; using UnityEngine; public class ScoreService : IScoreService { public event Action OnScoreChange; public int score { get; private set; } public int highScore { get; private set; } = PlayerPrefs.GetInt("HighScore"); public void AddScore() { score += 5; if (score>highScore) { SetNewHighScore(); } OnScoreChange?.Invoke(score); } private void SetNewHighScore() { highScore = score; PlayerPrefs.SetInt("HighScore", highScore); PlayerPrefs.Save(); } } public interface IScoreService { int score { get; } int highScore { get; } event Action OnScoreChange; void AddScore(); }