Clickable items
The IClickable is a component interface that adds a click event to a game object. Such objects can be either 3D elements inside the game scene, or 2D elements like on an user inteface.
The input system should be responsible for determining which object was clicked.
3D
Ray ray = camera.ScreenPointToRay(mousePosition);
if (Physics.Raycast(ray, out var hit))
{
var clickable = hit.GameObject.GetComponent<IClickable>();
clickable?.OnClick(...);
}
2D
var worldPos = camera.ScreenToWorld(mousePosition);
var hit = physics2D.OverlapPoint(worldPos);
var clickable = hit?.GameObject.GetComponent<IClickable>();
clickable?.OnClick(...);
Notice that click handling is identical after the picking phase. Only the hit testing differs.