⚙️
FPS Framework
Asset StoreFab
  • Get Started
    • Welcome!
    • Setup
  • Tutorials
    • Character
      • First-Person Controller
      • Inventory
      • Firearm
        • Basics
        • Advanced
        • Other
          • Spray pattern
          • Attachment System
          • Projectile System
      • Explosive
    • Systems
      • Audio System
      • Animation System
      • Interactions
        • Pickable
      • Save System
      • Settings System
    • Tools
      • Extension Methods
    • UI
      • FPS Counter
      • Get Name
      • Image Size Fitter
  • Other
    • Full Change Log
      • 2025 Change Log
      • 2024 Change Log
      • 2023 Change Log
      • 2022 Change Log
Powered by GitBook
On this page
  • Quick start
  • Coding an interactable

Was this helpful?

  1. Tutorials
  2. Systems

Interactions

An advanced interactions system based based on interfaces.

PreviousAnimation SystemNextPickable

Last updated 4 months ago

Was this helpful?

The interaction system in the FPS Framework is both powerful and easy to use, making it an essential feature for any FPS game. It provides a quick and efficient way for players to interact with objects in their environment, enhancing gameplay and immersion.

Quick start

You can quickly create an interaction using the Interactable component. Simply attach it to a GameObject and ensure it's set to the correct layer (the default interaction layer is Interactable) and attach a collider. This allows you to set up fast and seamless interactions in just seconds.

For testing, attach the Interactable class to a cube in your scene.

To test if the interaction works, add any action to the OnInteract event in the Interactable class. For this quick start, simply disable the cube when interacted with.

Now, when you approach the cube and press the Interact button, it should disappear.

Coding an interactable

To quickly code an Interactable this, create a new script and add the FPS Framework using text.

using Akila.FPSFramework;

public class DisableCubeInteraction : MonoBehaviour
{
    
}

Then implement the interface "IInteractable" like this:

public class DisableCubeInteraction : MonoBehaviour, IInteractable
{
    //The interaction name to show e.g Pickup, Open, Close, etc...
    public string GetInteractionName()
    {
        throw new System.NotImplementedException();
    }

    //The code to call when the interaction happens
    public void Interact(InteractablesManager source)
    {
        throw new System.NotImplementedException();
    }
}

Add any text in the GetInteractionName() like this:

//The interaction name to show e.g Pickup, Open, Close, etc...
public string GetInteractionName()
{
    return "Disable";
}

Now if you go back in unity and approach this interactable you should see your text appear.

For the interaction itself, add a message (e.g., print) inside the Interact() method. When you trigger the interaction, you should see the message appear. For this demo, you can disable the cube instead of making it disappear.

//The code to call when the interaction happens
public void Interact(InteractablesManager source)
{
    Debug.Log("Disabled!");

    gameObject.SetActive(false);
}

If you return to the cube, approach it, and press the interact button, the cube should disappear.