Hey All,
In my project I have objects for the player to interact with (Doors, Items to pick up, etc…) and what I’m wanting to happen is when the player looks an item a “Interaction Prompt” pops up with different text depending on the item -“Collect” if its an item to Pick up, “Open” if its a door etc.
I also want it so that when the player looks away from the object the “Interaction Prompt” disappears.
so far I’ve made a “Base Interactable” that all my objects inherit from.
This “Base Interactable” implements two interfaces, a “Interaction interface”, and A “Display Prompt” Interface.
Both have various functions for validation and to allow me to decide if I want to turn the option to interact on or off at anypoint.
The Base Interactable also have a UI widget attached to it so that the “Interaction Prompt” is displayed on the item rather:
Anyway I’ve managed to get to the point where I have the “Interaction Prompt” appearing and disappearing when the player is looking at the item and when looking away, but I’m just wondering if I could be doing this a better way?
So far I’m running a Line trace on the “Event Tick” tick, if it hits an object is validates if its an interactable object and if it can be interacted with, if both those conditions are true I’m storing a reference to the item that’s being looked at (for use if the player decided to interact with the item)and then I’m setting the visibility of the Item Widget to true, when the player looks away (Raycast hit is false) then I’m setting the widget on the stored reference to not be visible and clearing the reference
Essentially I’m little concerned about how much I’m running on the “Tick Event” and if I could make this cleaner? or if there is a better way of doing this all together?
Any help would be much appreciated!