-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreManager.cs
More file actions
43 lines (35 loc) · 824 Bytes
/
ScoreManager.cs
File metadata and controls
43 lines (35 loc) · 824 Bytes
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
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
public static ScoreManager Instance { get; private set; }
[Header("UI")]
public Text scoreText; // Drag your ScoreText here in the Inspector
[Header("Score")]
public int score = 0;
void Awake()
{
if (Instance != null && Instance != this) { Destroy(gameObject); return; }
Instance = this;
// Optional: DontDestroyOnLoad(gameObject);
}
void Start()
{
ResetScore();
}
public void ResetScore()
{
score = 0;
UpdateUI();
}
public void AddScore(int amount)
{
score += amount;
UpdateUI();
}
void UpdateUI()
{
if (scoreText != null)
scoreText.text = "Score: " + score;
}
}