public void OnUpHandler() { Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit)) { IClickable clickable = hit.transform.GetComponent <IClickable>(); clickable?.OnUp(); // Do something with the object that was hit by the raycast. } }