using System.Collections; using System.Collections.Generic; using UnityEngine; public class Raycasting : MonoBehaviour { [SerializeField] Transform playerCamera; [SerializeField] int seeDistance; Interactable curretInteractable; void Update() { bool Raycast = Physics.Raycast( playerCamera.position, playerCamera.TransformDirection(Vector3.forward), out RaycastHit hitInfo, seeDistance ); Debug.DrawRay( playerCamera.position, playerCamera.TransformDirection(Vector3.forward) * seeDistance, Color.green ); if (Raycast) { Debug.Log(hitInfo.transform.name); if (hitInfo.transform.TryGetComponent(out curretInteractable)) { } else { curretInteractable = null; } } else { curretInteractable = null; } } void OnInteract() { if(curretInteractable!=null) { curretInteractable.Interact(); } } }