18 lines
572 B
C#
18 lines
572 B
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class TreasureItem : MonoBehaviour
|
||
|
|
{
|
||
|
|
private void OnTriggerEnter(Collider other)
|
||
|
|
{
|
||
|
|
// Kiểm tra xem thứ chạm vào có script PlayerInventory không
|
||
|
|
PlayerInventory player = other.GetComponentInParent<PlayerInventory>();
|
||
|
|
if (player != null && !player.hasTreasure)
|
||
|
|
{
|
||
|
|
player.hasTreasure = true;
|
||
|
|
Debug.Log("Đã nhặt kho báu!");
|
||
|
|
|
||
|
|
// Làm vật phẩm biến mất
|
||
|
|
gameObject.SetActive(false); // Hoặc Destroy(gameObject);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|