LeeSin
LeeSin

Reputation: 9

(MRTK2) How to Use the onClick Events for custom Scripts?

I'm new to Unity and especially AR programming with the hololens. I use the mrtk2 and I get figure out, how to use the Buttons to work with my own script.

I read the documentation of the Interactable component but I still didn't get it.

What I want: Use a Button to spawn a new GameObject (cube f.e) What I did so far: - I use the PressableButtonHololens2 Prefab with an Interactable component There is the OnClick event, which triggers a event if the Button get pushed.

My question now: How do I add my own script to the onClick event? I cant drag it simply to it. I already extended my script to the ReceiverBase class, but it still not appears in the menu where I can choose the event.

Best regards and thank you for the help

Upvotes: 0

Views: 3084

Answers (2)

psumner
psumner

Reputation: 21

Add a script that contains a public method to the button (or any other Gameobject). Drag and drop the Gameobject containing the script to the Events component of the button. The public method you created in the script can then be selected from the on click event dropdown.

Upvotes: 0

Perazim
Perazim

Reputation: 1549

Idk if I understood you right, but if yes, then this neither a unity question nor an mrtk question. Its a basic programming question...put your script where you want, as long as you can reference it. Then call in your onClick-method yourScript.yourMethod();

Upvotes: 1

Related Questions