Files
BABA_YAGA/Assets/Scripts/TreasureItem.cs
2026-06-03 04:32:58 +07:00

41 lines
1.1 KiB
C#

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<PlayerInventory>();
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);
}
}