Interactions
An advanced interactions system based based on interfaces.
Last updated
Was this helpful?
An advanced interactions system based based on interfaces.
Last updated
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.
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.
To quickly code an Interactable this, create a new script and add the FPS Framework using text.
Then implement the interface "IInteractable" like this:
Add any text in the GetInteractionName() like this:
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.
If you return to the cube, approach it, and press the interact button, the cube should disappear.