-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalScoreSO.cs
More file actions
44 lines (36 loc) · 1.08 KB
/
GlobalScoreSO.cs
File metadata and controls
44 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using UnityEngine;
[CreateAssetMenu(fileName = "GlobalScore", menuName = "Game/Global Score")]
public class GlobalScoreSO : ScriptableObject
{
[SerializeField] private int score = 0;
public System.Action<int> OnScoreChanged;
public int Score => score;
public void AddScore(int value)
{
if (value < 0)
{
Debug.LogWarning("Attempted to add negative value via AddScore. Use SubtractScore.");
return;
}
score += value;
Debug.Log($"[GlobalScore] Added {value} points. Total: {score}");
OnScoreChanged?.Invoke(score);
}
public void SubtractScore(int value)
{
score -= value;
Debug.Log($"[GlobalScore] Subtracted {value} points. Total: {score}");
OnScoreChanged?.Invoke(score);
}
public void ResetScore()
{
score = 0;
Debug.Log("[GlobalScore] Score reset to 0");
OnScoreChanged?.Invoke(score);
}
public void OnEnable()
{
// Uncomment for auto-reset at game start:
// score = 0;
}
}