using System.Dynamic;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerInteract : MonoBehaviour
{
private Camera cam;
[SerializeField]
private float distance = 3f; //trong 3 block ,neu nhin vao se hien
[SerializeField]
private LayerMask mask;
private PlayerUI playerUI;
private InputManager inputManager;
// Start is called before the first frame update
void Start()
{
cam = GetComponent<PlayerLook>().cam;
playerUI = GetComponent<PlayerUI>();
inputManager = GetComponent<InputManager>();
}
// Update is called once per frame
void Update()
{
playerUI.UpdateText(string.Empty);;// làm tất cả chữ trước mặt biến mất rồi mời hiện ra use door
//tao 1 duong thang chinh giua camera, nham vao vatt the
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
Debug.DrawRay(ray.origin,ray.direction * distance);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, distance,mask))
{
if (hitInfo.collider.GetComponent<Interactable>());
{
Interactable interactable = hitInfo.collider.GetComponent<Interactable>().promptMessage;
playerUI.UpdateText(interactable.promptMessage);
if (inputManager.onFoot.Interactor.triggered)
{
interactable.OnSelectEntering();//nguyen lai la BaseInteract
}
}
}
}
}