- Home /
Best pattern for activating something
Hello, I am trying to implement a Player controller and it will be able to touch things. It is a FPS, so the idea is to "touch" the objects pointed by the cursor in the middle of the screen.
Some objects in the scene will be touchable.
What I am doing is associating to all the Touchable items a script which implements the ITouchable Interface. Each one will be implement its own interface.
The point is... How to communicate between the Player Controller and those objects.
Imagine to raycast on mouse event: I can try a best effort GetComponent on the gameObject casted to the wanted Interface and call it if necessary.
Obviously, everything which is implemented in the Touch interface of the "receiver" must be asynchronous, since this is blocking.
Answer by siaran · Feb 23, 2015 at 11:38 PM
Raycasting from your mouse to your object and getting the component is one way to do it.
You can also check out the OnMouseDown, OnMouseEnter, etc. methods of MonoBehaviour class (in this case, you would want to set Screen.lockCursor = true to have it centered in your screen).
Your answer
![](https://koobas.hobune.stream/wayback/20220613184050im_/https://answers.unity.com/themes/thub/images/avi.jpg)