-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.cs
More file actions
44 lines (39 loc) · 1.12 KB
/
UI.cs
File metadata and controls
44 lines (39 loc) · 1.12 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;
using TMPro;
using UnityEngine.SceneManagement;
public class UI : MonoBehaviour
{
[SerializeField] private TMP_Text movesText;
[SerializeField] private TMP_Text pointsText;
[SerializeField] private int moves;
private int endScene = 1;
public static int points;
private void OnEnable()
{
ChangeItemCell.OnMoveDone += ReduseMoves;
MatchChecker.OnMatchMade += IncreasePoints;
}
private void OnDisable()
{
ChangeItemCell.OnMoveDone -= ReduseMoves;
MatchChecker.OnMatchMade -= IncreasePoints;
}
private void Start()
{
points = 0;
pointsText.text = points + " points";
movesText.text = "Moves left " + moves;
}
private void IncreasePoints(int cellItemValue)
{
points += cellItemValue;
pointsText.text = points + " points";
}
private void ReduseMoves()
{
moves--;
movesText.text = "Moves left " + moves;
if (moves <= 0) EndGame();
}
private void EndGame() => SceneManager.LoadScene(endScene);
}