using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerInteract : MonoBehaviour
{
public Camera cam;
[SerializeField]
private float distance = 3f;
[SerializeField]
private LayerMask mask;
public PlayerUI playerUI;
// Start is called before the first frame update
void Start()
{
cam = GetComponent<Camera>();
playerUI = GetComponent<PlayerUI>();
}
// Update is called once per frame
void Update()
{
playerUI.UpdateText(string.Empty);
if (cam != null)
{
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
Debug.DrawRay(ray.origin, ray.direction * distance, Color.red);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, distance, mask))
{
if (hitInfo.collider.GetComponent<Interactable>() != null)
{
playerUI.UpdateText(hitInfo.collider.GetComponent<Interactable>().promptMessage);
}
}
}
}
}