Creating new interactions
Last updated
Last updated
Let's create a new simple pick-up interaction, that will use .
Create a new script. For more convenience end it with Interactable or Interaction.
Extends from Interactable
You will see red line, which indicate that scripts contains errors. That's right, once we extend from
Interactable
, we need to implement some base methods.
Implementing required methods
We only need primary action for this interaction, so we set UsePrimaryActionHint()
to return true, and also make GetPrimaryHintText()
return hint text "Pick object".
For UseSecondaryActionHint()
and GetSecondaryHintText()
we return default values.
Also, we need to override IsUnsubscribeBlocked()
, but, because we don't want to block interaction, we return false.
Now, let's override OnInteractPrimary()
and add some logics to it.
Also, we created a new field, inventoryItemData
to set it from inspector.
Ok, we have created script. Now, let's setup it in Unity
Create new gameobject, or drop from project tab.
It's important to have an mesh renderer on object. Also, remember to add and collider, of any type
Change layer, from default to Interactable
Add Outline
component to object, and disable it (we don't need that outline to be visible at start)
Finally, add our interaction PickUpInteractable
, and set inventory item data with and corresponding item
Congrats . You created your first interaction. To get more information about interaction creation, and what you can do, see Interaction anatomy