32 lines
687 B
C#
32 lines
687 B
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class ScoreManager : MonoBehaviour
|
|
{
|
|
public int Score = 0;
|
|
private Label _scoreLabel;
|
|
|
|
public static System.Action<int> OnScoreChanged;
|
|
|
|
|
|
public void AddPoints(int points)
|
|
{
|
|
Score += points;
|
|
UpdateScoreDisplay();
|
|
Debug.Log("Score updated: " + Score);
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
var root = GetComponent<UIDocument>().rootVisualElement;
|
|
// Find your Label by name in the UXML
|
|
_scoreLabel = root.Q<Label>("Score");
|
|
}
|
|
|
|
private void UpdateScoreDisplay()
|
|
{
|
|
OnScoreChanged?.Invoke(Score);
|
|
_scoreLabel.text = $"Score: {Score}";
|
|
}
|
|
}
|