-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreScript.cs
More file actions
71 lines (60 loc) · 1.71 KB
/
Copy pathScoreScript.cs
File metadata and controls
71 lines (60 loc) · 1.71 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using UnityEngine;
using TMPro;
using System.Collections;
public class ScoreScript : MonoBehaviour
{
[SerializeField]
private int scoreNum = 500;
public int currentScore;
private bool isDoublePoints = false;
public TextMeshProUGUI score;
public TextMeshProUGUI highScore;
// Duration for double points to be active
private float doublePointsDuration = 25f;
void Start()
{
scoreNum = 500;
Debug.Log("Starting with " + scoreNum);
// Subscribe to the DoublePoints event
DoublePoints.onCollected += ActivateDoublePoints;
score.text = "" + scoreNum;
}
void OnDestroy()
{
// Unsubscribe from the DoublePoints event to avoid memory leaks
DoublePoints.onCollected -= ActivateDoublePoints;
}
void Update()
{
}
public void AddScore(int amount)
{
if (isDoublePoints && amount > 0)
{
scoreNum += amount * 2;
}
else
{
scoreNum += amount;
}
score.text = scoreNum.ToString();
}
// Method to activate double points
private void ActivateDoublePoints()
{
isDoublePoints = true;
// Start a coroutine to disable double points after the duration
StartCoroutine(DisableDoublePointsAfterTime(doublePointsDuration));
}
// Coroutine to disable double points
private IEnumerator DisableDoublePointsAfterTime(float duration)
{
yield return new WaitForSeconds(duration);
isDoublePoints = false;
}
public int GetCurrentScore()
{
currentScore = scoreNum;
return currentScore;
}
}