using UnityEngine; using System.Collections; public class TreasureItem : MonoBehaviour { [Header("Cài đặt UI thông báo")] public GameObject notificationText; private void Start() { if (notificationText != null) notificationText.SetActive(false); } private void OnTriggerEnter(Collider other) { // Tìm PlayerInventory ở đối tượng hoặc cha của nó PlayerInventory player = other.GetComponentInParent(); if (player != null) { player.treasuresCollected += 1; Debug.Log("Đã nhặt rương! Tổng cộng: " + player.treasuresCollected); if (notificationText != null) { StopAllCoroutines(); StartCoroutine(ShowNotification()); } // Biến mất rương gameObject.SetActive(false); } } IEnumerator ShowNotification() { notificationText.SetActive(true); yield return new WaitForSeconds(2f); notificationText.SetActive(false); } }