using UnityEngine; using TMPro; // Dùng UnityEngine.UI nếu bạn xài Text thường public class ScoreManager : MonoBehaviour { public TextMeshProUGUI scoreText; // Kéo UI Text điểm số vào đây private int currentScore = 0; void Start() { currentScore = 0; UpdateScoreUI(); // CHẨN ĐOÁN LỖI: Collider col = GetComponent(); if (col == null) Debug.LogError("LỖI NẶNG: Object này (" + gameObject.name + ") CHƯA CÓ COLLIDER. Hãy add Box Collider ngay!"); else if (!col.isTrigger) Debug.LogWarning("CẢNH BÁO: Collider của rổ chưa tích 'Is Trigger'. Hãy tích vào!"); Debug.Log("Script ScoreManager đang hoạt động trên: " + gameObject.name + ""); } // Bắt va chạm kiểu Trigger (Xuyên qua) private void OnTriggerEnter(Collider other) { GhiDiem(other.gameObject, "TRIGGER"); } // Bắt va chạm kiểu Vật lý (Đập vào nhau) - Dự phòng nếu bạn chưa tích Is Trigger private void OnCollisionEnter(Collision collision) { GhiDiem(collision.gameObject, "PHYSICS"); } void GhiDiem(GameObject obj, string type) { Debug.Log("PHÁT HIỆN VA CHẠM [" + type + "] với: " + obj.name + " | Tag: " + obj.tag); if (obj.CompareTag("Ball") || obj.name.Contains("Sphere") || obj.name.Contains("ball")) { currentScore += 2; UpdateScoreUI(); Debug.Log("===> GHI ĐIỂM THÀNH CÔNG! Điểm hiện tại: " + currentScore + ""); Destroy(obj, 0.2f); } } void UpdateScoreUI() { if (scoreText != null) { scoreText.text = "Score: " + currentScore; } else { Debug.LogWarning("ScoreText chưa được kéo vào ScoreManager!"); } } }