using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemChest : Item {
    public GameSound notifySound;
    public GameObject infoPrefab;

    public Transform transfGFX;
    static Player playerBuf;

    bool playerInRange = false;

    KeyCode openKey = KeyCode.F;

    private void Update() {
        if(playerInRange) {
            if(Input.GetKey(openKey)) {
                Open();
            }
        }    
    }

    void Open() {
        GameUI.inst.chestUI.SetActive(true);
    }

    private void OnTriggerEnter(Collider other) {
        playerBuf = other.GetComponent<Player>();

        if(playerBuf != null) {
            notifySound.Play();
            Instantiate(infoPrefab, transfGFX.position + Vector3.up, Quaternion.identity);
            playerInRange = true;
        }
    }

    private void OnTriggerExit(Collider other) {
        playerBuf = other.GetComponent<Player>();

        if(playerBuf != null) {
            playerInRange = false;
        }
    }
}
