Survival Template Pro
Roadmap
  • Welcome!
  • Getting Started
    • Installation Guide
      • Demo Maps
    • Scene Setup
    • Frequently Asked
    • Integrations
  • Player
    • Character
    • Modules & Behaviours
      • Inventory
        • Item Container
      • Movement
      • Camera
      • Health
      • Building
      • Object Carry
      • Wieldable
      • Interaction
      • Crafting
      • Sleep
      • Audio
  • User Interface
    • UI Behaviours Manager
    • Behaviours
      • UI_Inventory
      • UI_Damage
      • UI_Vitals
      • UI_Wieldables
      • UI_Interaction
      • UI_Sleep
  • Interaction
    • Interactable
      • Demo Interactables
    • Extension
  • Inventory
    • Create Item
      • Item Info
      • Item Settings
      • Properties & Tags
      • Item Pickup
  • Wieldables
    • Overview
  • Surfaces
    • Create Surface
    • Code Examples
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Interaction

Extension

Example (inherit from Interactable)

namespace SurvivalTemplatePro
{
    public class InteractableTest : Interactable
    {
        public override void OnInteract(ICharacter character)
        {
            base.OnInteract(character);

            // Do something when a character interacts with this.
            // e.g. press a button
        }

        public override void OnHoverStart(ICharacter character)
        {
            base.OnHoverStart(character);

            // Do something when a character starts looking at this object.
            // e.g. Enable outline effect
        }

        public override void OnHoverEnd(ICharacter character)
        {
            base.OnHoverEnd(character);

            // Do something when a character stops looking at this object.
            // e.g. Disable outline effect
        }
    }
}

Example (Implement the IInteractable interface)

namespace SurvivalTemplatePro
{
    public class InteractableTest : MonoBehaviour, IInteractable
    {
        public bool InteractionEnabled { get; set; }
        public string InteractionText => "Interaction Text";
        public string DescriptionText => "Description Text";

        public float HoldDuration => 0f;

        public event UnityAction onInteracted;
        public event UnityAction onDescriptionTextChanged;
        public event UnityAction<bool> onInteractionEnabledChanged;


        public void OnInteract(ICharacter character)
        {
            // Do something when a character interacts with this.
            // e.g. press a button
        }

        public void OnHoverStart(ICharacter character)
        {
            // Do something when a character starts looking at this object.
            // e.g. Enable outline effect
        }

        public void OnHoverEnd(ICharacter character)
        {
            // Do something when a character stops looking at this object.
            // e.g. Disable outline effect
        }
    }
}

PreviousDemo InteractablesNextCreate Item

Last updated 3 years ago

Was this helpful?