Added Scoring
added ability to get rid of treats and increment a score
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user