Interactable w/ other actions

What would you recommend as the best way to handle the following situation:
  • There's a gameobject that the player can pick up that contains Interactable.cs, ItemObject.cs, and ItemPickup.cs tied to an action button (let's say spacebar).
  • The player can also perform actions, such as digging a hole, (unrelated to UIS) using the same action button (spacebar). These are currently called in a player script with the Update() monobehavior using a simple GetButtonDown method.
  • Ideally, I'd like the player to be able to pickup the item, but *not* execute the action in the player script Update() method. Then once the item is picked up, the next time they hit the action button, they can perform the action in the player script.
This would be super easy if I wasn't utilizing the built in IInteractor, but it's so useful I'm using it quite frequently. My initial thinking was to have my base player script (that has my own actions in it) "call" the interactable script on the gameobject, but I'm not sure the best way to do that.

I didn't see anything in the documentation or code comments that spoke to this, but apologies if I missed it!

Thoughts/ideas?

Thanks!
 
If I were you I would bring both functionalities in a single place such that you can choose the priority. In both case the underling action is an "interaction" whether it is pickup or dig.

So you could either put the interact function in your palyer, or you could take out dig and put it in a more generic interaction functionality.

For example you could replace the InventoryInteractor script by a custom script, as long as it inherits the "IInteractorWithInventory" interface it should work.

Of course you would need to convert your dig triggers into the Interactables...


Another solution would be to make the interactables list within InventoryInteractor public... this way your character could check if the InventoryInteractor can interact with anything, and if not it should do the dig.

Code:
public IInteractable SelectedInteractable => m_SelectedInteractable;
public IReadOnlyList<IInteractable> Interactables => m_Interactables;

I'll add those in the next patch.

Make sure to remove the input for interacting in the InventoryStandardInput inspector, and instead call Interact from the player script
 
Top