using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Playerinteract : MonoBehaviour
{
private Camera cam;
[SerializeField]
private float distance = 3f;
[SerializeField]
private LayerMask mask;
private Playerui playerui;
private PlayerInput playerinput;
// Start is a before the first frame update
void Start()
{
cam = GetComponent<Playerlook>().cam;
playerui = GetComponent<Playerui>();
playerinput = new();
playerinput.Enable();
}
// Update is called once per frame
void Update()
{
playerui.updatetext(string.Empty);
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
Debug.DrawRay(ray.origin, ray.direction * distance);
RaycastHit hitinfo; // variable to store our collision info //
if (Physics.Raycast(ray, out hitinfo, distance, mask))
{
if(hitinfo.collider.GetComponent<Interactable>() != null)
{
Interactable interactable = hitinfo.collider.GetComponent<Interactable>();
playerui.updatetext(interactable.promptmessage);
if(playerinput.Onfoot.Interact.triggered)
{
interactable.baseinteract();
}
}
}
}
}