Easy Interaction System
  • 👋Welcome
  • 🚀Installation
    • New Project Setup
  • Setup new scene
  • Creating new interactions
    • Interaction anatomy
      • Input hints
        • More additional action hints
        • UpdateHints
      • Keep action active
      • Analog of OnEnable and OnDisable interaction
      • Analog of Update
      • Debug active interactions
  • Suport
  • Additional Systems
    • Inventory System
    • Notification System
Powered by GitBook
On this page

Creating new interactions

PreviousSetup new sceneNextInteraction anatomy

Last updated 1 year ago

Let's create a new simple pick-up interaction, that will use .

  1. Create a new script. For more convenience end it with Interactable or Interaction.

  1. 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.

  1. Implementing required methods

public override bool UsePrimaryActionHint() => true;
public override string GetPrimaryHintText() => "Pick object";

public override bool UseSecondaryActionHint() => false;
public override string GetSecondaryHintText() => default;

public override bool IsUnsubscribeBlocked() => false;

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.

  1. Now, let's override OnInteractPrimary() and add some logics to it.

Also, we created a new field, inventoryItemData to set it from inspector.

[SerializeField] private InventoryItemData inventoryItemData;
public override void OnInteractPrimary()
{
    InventoryController.AddToInventory(inventoryItemData);
    Destroy(gameObject);
}

  1. 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

🎉
Inventory System