- Home /
select method to access from other component, in the editor?
I'm making an interaction system. So far I've settled on having a trigger volume prefab with the script on it in the game, which accepts input from the player when he's in it. It gets parented to other prefabs, searches in them another script component "interaction handler", and sends them a message if the player pressed a button while inside the trigger:
if (currentHandler != null)
{
currentHandler.SendMessageUpwards("InteractEvent");
}
Now the interaction handler component should take care of the interactions, but it's planned to be attached to all sorts of things - doors, lights, NPCs, and so on. So what I wanted to do is to be able to create a variable where inside the Editor I could assign or type in what method in which component I want to run. So in Door it would be DoorOpen(); in Door Controller component, for instance, in NPC it would be StartConversation(); in Dialogue Controller component, and, if possible, in case of something like a lever or a button, it would actually be a function in a component of another object in the scene entirely. How do I do that?
Answer by Fariborzzn · Dec 18, 2019 at 12:12 AM
Hey i think you should look after interface..
Your interface will be interactable so every script that inherent from it should have popoperty and function you define in your interface .. they all have function called interact but not doing same task!
take a look at interface and observe pattern
Yw Happy to hear that also check unity event system and delegate they are the tools you asked for
Your answer
