using UnityEngine; using TMPro; using StarterAssets; public class Interaction : MonoBehaviour, IInteractable { [SerializeField] TextMeshProUGUI interactionPrompt; [SerializeField] float interactRange = 3f; StarterAssetsInputs starterAssetsInputs; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { starterAssetsInputs = GetComponent(); interactionPrompt.gameObject.SetActive(false); interactionPrompt.text =""; } // Update is called once per frame void Update() { RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, interactRange)) { IInteractable interactable = hit.transform.GetComponent(); if (interactable != null) { interactionPrompt.gameObject.SetActive(true); interactionPrompt.text = interactable.GetInteractionPrompt(); //Debug.Log("Looking at interactable: " + hit.transform.name); if (!starterAssetsInputs.interact) return; { interactable.Interact(gameObject); interactionPrompt.gameObject.SetActive(false); starterAssetsInputs.InteractInput(false); } interactionPrompt.gameObject.SetActive(false); } else { interactionPrompt.gameObject.SetActive(false); interactionPrompt.text = ""; } } else { interactionPrompt.gameObject.SetActive(false); interactionPrompt.text = ""; } } public void Interact(GameObject interactor) { Debug.Log("Interacted with " + gameObject.name); } public bool CanInteract(GameObject interactor) { throw new System.NotImplementedException(); } public string GetInteractionPrompt() { throw new System.NotImplementedException(); } public void OnHighlight() { throw new System.NotImplementedException(); } public void OnUnhighlight() { throw new System.NotImplementedException(); } }