game(scripts): standardise TrashBinTracker

This commit is contained in:
Mark Joshwel 2025-02-15 00:36:32 +08:00
parent 8e1f74a92b
commit 5417c57b66

View file

@ -8,24 +8,24 @@ using UnityEngine;
public class TrashBinTracker : MonoBehaviour public class TrashBinTracker : MonoBehaviour
{ {
private BedroomTask bedroomTask; private BedroomTask _bedroomTask;
private void Start() private void Start()
{ {
// Find the BedroomTask script in the scene // Find the BedroomTask script in the scene
bedroomTask = FindObjectOfType<BedroomTask>(); _bedroomTask = FindObjectOfType<BedroomTask>();
if (bedroomTask == null) Debug.LogWarning("BedroomTask script not found in the scene!"); if (_bedroomTask == null) Debug.LogWarning("BedroomTask script not found in the scene!");
} }
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
if (other.CompareTag("TrashBin")) if (!other.CompareTag("TrashBin")) return;
if (_bedroomTask != null)
{ {
if (bedroomTask != null) _bedroomTask.CollectTrash();
{ Debug.Log("🗑️ Trash thrown in the bin! Count: " + _bedroomTask.trashCollected);
bedroomTask.CollectTrash();
Debug.Log("🗑️ Trash thrown in the bin! Count: " + bedroomTask.trashCollected);
Destroy(gameObject); Destroy(gameObject);
} }
else else
@ -34,4 +34,3 @@ public class TrashBinTracker : MonoBehaviour
} }
} }
} }
}