Interactable

Allows interaction between the Player ( Thanks to the InteractManager ) and this object.

Using Interactable.cs, there are different ways you can achieve custom interactions, simple and advanced.

  1. Attach the component to your interactable object:

  • For simple interactable objects assign the Interactable Component to an object with a box collider, you can subscribe to the OnInteract event to add your custom behaviour.

  • For advanced interactable objects:

    • Create a new C# script.

    • This new C# script must inherit from Interactable.cs

    • override the base Interact method from Interactable.cs

 public class CustomInteractable : Interactable
    {
        
        public override void Interact(Transform player)
        {
            // Custom code on interact
             base.Interact(player);
        }

    }
  1. Ensure the Interactable Layer is assigned to the same object that contains the Collider & Interactable Component ( or script that inherits from it )

For the Interactable.cs:

  • interactText

  • interactableEvents

  • instantInteraction: If true, Progress Required To Interact from InteractManager will be overrided and set to instant interaction only for this interactable.

Functions | Interactable.cs

player ( Transform ) | Protected ( only accessible from scripts that inherit from Interactable.cs )

Player that interacts with the Interactable.

Since 1.3, InteractManager passes the player directly to the Interactables.

Interact(Transform player) -> Virtual Method

Interact with the Interactable object.

  • player: Transform that interacts with this interactable

Highlight() -> Virtual Method

Triggers when an Interactable is highlighted.

  • player: Transform that interacts with this interactable

Unhighlight() -> Virtual Method

Triggers when an interactable is no longer highlighted.

  • player: Transform that interacts with this interactable

IsForbiddenInteraction(WeaponController weaponController) -> Virtual Method, Returns a Boolean

Returns whether the interaction is valid or not. Returns false by default, meaning that the interaction can be performed.

  • weaponController: You can use the WeaponController to access specific components or properties to determine if an interaction is valid, in case you need it.

Last updated