update lại về cam và logic
This commit is contained in:
@@ -6,20 +6,55 @@ 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<Collider>();
|
||||
if (col == null)
|
||||
Debug.LogError("<color=red>LỖI NẶNG: Object này (" + gameObject.name + ") CHƯA CÓ COLLIDER. Hãy add Box Collider ngay!</color>");
|
||||
else if (!col.isTrigger)
|
||||
Debug.LogWarning("<color=yellow>CẢNH BÁO: Collider của rổ chưa tích 'Is Trigger'. Hãy tích vào!</color>");
|
||||
|
||||
Debug.Log("<color=white>Script ScoreManager đang hoạt động trên: " + gameObject.name + "</color>");
|
||||
}
|
||||
|
||||
// Bắt va chạm kiểu Trigger (Xuyên qua)
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
// Kiểm tra xem vật lọt qua rổ có phải là bóng không
|
||||
if (other.CompareTag("Ball"))
|
||||
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; // Cộng 2 điểm
|
||||
currentScore += 2;
|
||||
UpdateScoreUI();
|
||||
|
||||
// (Tùy chọn) Thêm hiệu ứng âm thanh hoặc Particle vào đây
|
||||
Debug.Log("<color=cyan>===> GHI ĐIỂM THÀNH CÔNG! Điểm hiện tại: " + currentScore + "</color>");
|
||||
Destroy(obj, 0.2f);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateScoreUI()
|
||||
{
|
||||
scoreText.text = "Score: " + currentScore;
|
||||
if (scoreText != null)
|
||||
{
|
||||
scoreText.text = "Score: " + currentScore;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("ScoreText chưa được kéo vào ScoreManager!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user