Hertzole / gold-player

A first person player controller for Unity.
MIT License
160 stars 16 forks source link

Interaction #28

Closed VenomMeme closed 5 years ago

VenomMeme commented 5 years ago

Hey, I'm trying to wrap my head around using the interaction part. The farthest I've gotten was making the interact prompt disappear. Please help.

Hertzole commented 5 years ago

Hello!

I'll gladly try to help you!

The interaction system should be pretty simple to use. You attach the GoldPlayerInteraction component on your actual player and set the values there that you would like.

Then on the objects you want to interact with, you add the GoldPlayerInteractable component and there you can set some additional values, and the most important one being the OnInteract event. It functions just like Unity's UI buttons. You drag in an object and select the function it should execute when the object has been interacted with.
You can also set the interaction event through code by accessing OnInteract in the GoldPlayerInteractable class and doing AddListener.

To make the UI work with it (using GoldPlayerUI) you just need to add the GoldPlayerUI component to your UI objects (like your canvas) and set the values there. The most important being 'Player Interaction' (or just leave it empty and allow it to auto find the player) as that makes it work.
The interaction box is what will get toggled to show the interaction prompt. It can be a whole box or just the same label you're using on the 'Interaction Label'.

If you have any other questions, just ask away! I'll gladly help you! :)

VenomMeme commented 5 years ago

Thank you so much! I'm working on doors right now for my game. I am having a bit of trouble, but I'm just gonna do some research on Unity animations before resulting to you.