Added Scoring

added ability to get rid of treats and increment a score
This commit is contained in:
Walter
2026-01-31 16:59:41 -06:00
parent f958700a1c
commit 7cf2361297
43 changed files with 10415 additions and 344 deletions
+18
View File
@@ -0,0 +1,18 @@
using UnityEngine;
public class BasketController : MonoBehaviour
{
public ScoreManager scoreManager;
private void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("2D Solid hit with: " + collision.gameObject.name);
if (collision.gameObject.CompareTag("Interactable"))
{
scoreManager.AddPoints(1);
GameObject.Destroy(collision.gameObject);
}
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bba2c7dd7c77e0a4ab1157bab0c5bd0f
+31
View File
@@ -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}";
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d6e51e2135855944dbc7ba0763ce1cba