Currently when I am trying to detect whether an object has been clicked / interacted with by the mouse, I create a script on that GameObject and then define void OnMouseDown() and apply functionality within. If I then want to trigger a function in another script that is not attached to the GameObject I call it through a GetComponent<>() reference.
Is there a way to add a callback to the OnMouseDown event from a script on another GameObject? Potentially in the same way delegates / events are allocated and invoked? Something such as: gameObjectReference.GetComponent<BoxCollider>().onmousedownevent += MyFunction; So that it automatically calls this function on mouse down?
Note: I know that you can use raycasting to achieve something similar, but my question is about attaching callbacks to the existing Unity event.
morewhich is apublic UnityEvent. it's "less than" one line of code, you just drag. - Fattie