Files
BABA_YAGA/Assets/Scripts/TreasureItem.cs

41 lines
1.1 KiB
C#
Raw Normal View History

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