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,30 +8,29 @@ using UnityEngine;
public class TrashBinTracker : MonoBehaviour
{
private BedroomTask bedroomTask;
private BedroomTask _bedroomTask;
private void Start()
{
// 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)
{
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);
Destroy(gameObject);
}
else
{
Debug.LogError("BedroomTask reference is missing!");
}
_bedroomTask.CollectTrash();
Debug.Log("🗑️ Trash thrown in the bin! Count: " + _bedroomTask.trashCollected);
Destroy(gameObject);
}
else
{
Debug.LogError("BedroomTask reference is missing!");
}
}
}