Hi, I’m new to scripting and trying to find out a proper and robust way to communicate between GameObjects.
Simple example, I want the Player GameObject being able to open a door with key-press, when inside the door’s trigger area.
I know the possibilities of direct referencing the gameObjects/classes.
But I’m wondering if there is a more simple, robust and performant way.
Basically, I don’t want the Player to have to know anything about it’s environment. But if the Player is within an interactable object’s trigger area, I want the Player to trigger something on the interactable, when pressing [F] for example.
The Player however should not need to know who this someone and something is what needs to happen.
Player should only know that it pressed the key and broadcast this fact out in some way.
GameObjects, whose trigger area is occupied by the Player should then receive the key-press signal and decide what to do.
I’m really struggling to find an answer to his. Even my paid Udemy courses lack this kind of information.
I tried around with Interfaces, but failed at finding a way to reference the door gameObject, without having the Player to know about its existence again.
I can imagine that there is a really simple way and I’m just totally blind.
Does anyone know a proper solution to this?
Regards
Massimo