Trigger OnClick() with raycast

I have an onclick action listener and I have input to be raycasting and clicking a button. My project is in VR so mouse clicking isn’t an option. Event onclick code is already written so I would like to get it to work with my input. Thanks in advance!

if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, raycastDistance))

if (hit.transform.gameObject.tag == "key") {
            Text text = hit.transform.gameObject.GetComponentInChildren<Text>();

I would take the code you have in onClick and put it into another method that’s public. Now, all your onClick has to do is call that method. Then, use text.NAMEOFOTHERMETHOD() instead of trying to invoke onClick.