update AI
This commit is contained in:
@@ -1,18 +1,41 @@
|
||||
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)
|
||||
{
|
||||
// Kiểm tra xem thứ chạm vào có script PlayerInventory không
|
||||
// Tìm PlayerInventory ở đối tượng hoặc cha của nó
|
||||
PlayerInventory player = other.GetComponentInParent<PlayerInventory>();
|
||||
if (player != null && !player.hasTreasure)
|
||||
|
||||
if (player != null)
|
||||
{
|
||||
player.hasTreasure = true;
|
||||
Debug.Log("Đã nhặt kho báu!");
|
||||
player.treasuresCollected += 1;
|
||||
Debug.Log("Đã nhặt rương! Tổng cộng: " + player.treasuresCollected);
|
||||
|
||||
if (notificationText != null)
|
||||
{
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(ShowNotification());
|
||||
}
|
||||
|
||||
// Làm vật phẩm biến mất
|
||||
gameObject.SetActive(false); // Hoặc Destroy(gameObject);
|
||||
// Biến mất rương
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ShowNotification()
|
||||
{
|
||||
notificationText.SetActive(true);
|
||||
yield return new WaitForSeconds(2f);
|
||||
notificationText.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user