Files
HelixJump/Assets/Scripts/Score/ScoreService.cs
2025-12-11 18:20:42 -08:00

36 lines
683 B
C#

using System;
using Unity.VisualScripting;
using UnityEngine;
public class ScoreService
{
public Action<int> 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);
}
}