using System; using Unity.VisualScripting; using UnityEngine; public class ScoreService { public Action onScoreUpdate; public int score { get; private set; } public int HighScore = PlayerPrefs.GetInt("HighScore", 0); public void AddScore() { score += 5; onScoreUpdate?.Invoke(score); if(score>HighScore) { SetHighScore(); } Debug.Log(score); } private void SetHighScore() { HighScore = score; PlayerPrefs.SetInt("HighScore",HighScore); PlayerPrefs.Save(); } public int GetHighscore() { return PlayerPrefs.GetInt("HighScore",0); } }