using UnityEngine; using System.Collections; using Hallucinate.Audio; public class TreasureItem : MonoBehaviour { [Header("Cài đặt UI thông báo")] public GameObject notificationText; // Text "Đã nhặt Cổ vật" [Header("Cài đặt Âm thanh")] public string pickupSound = "Item_Pickup"; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { PlayerInventory player = other.GetComponentInChildren(); if (player == null) player = other.GetComponentInParent(); if (player != null) { // 1. Tăng số lượng rương đang giữ player.treasuresCollected++; Debug.Log($"[Chest] NHẶT THÀNH CÔNG! Số rương hiện tại: {player.treasuresCollected}"); // 2. Cập nhật sao trên HUD ngay lập tức (Tìm FinishGate để mượn hàm update) FinishGate gate = Object.FindAnyObjectByType(); if (gate != null) { gate.UpdateStarsUI(player.treasuresCollected); } // 3. Kích hoạt trạng thái truy đuổi cho toàn bộ Enemy AI SetEnemiesAlertState(true); // 4. Chạy âm thanh nhặt đồ if (AudioManager.Instance != null) { AudioManager.Instance.Play(pickupSound, position: transform.position); } if (notificationText != null) { StopAllCoroutines(); StartCoroutine(ShowNotification()); } // Biến mất rương gameObject.SetActive(false); } } } private void SetEnemiesAlertState(bool state) { EnemyAI[] allEnemies = Object.FindObjectsByType(FindObjectsSortMode.None); foreach (EnemyAI enemy in allEnemies) { enemy.playerHasArtifact = state; } } IEnumerator ShowNotification() { notificationText.SetActive(true); yield return new WaitForSeconds(2f); notificationText.SetActive(false); } }