simple UI added
This commit is contained in:
35
Assets/Scripts/Score/ScoreService.cs
Normal file
35
Assets/Scripts/Score/ScoreService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user