Files
ggj2026/Assets/Scripts/ScoreManager.cs
Walter 7cf2361297 Added Scoring
added ability to get rid of treats and increment a score
2026-01-31 16:59:41 -06:00

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}";
}
}