-1

I am developing an App for Hololens 2 where I am spawning Interactables with properties read from a JSON Object. At the moment I am spawning them automatically on appstart but I want to create a Button that triggers the event manually. (Same goes for deleting them later)

I created a Button in my Scene and I have my spawning script in my Script Folder I am now struggling to connect my spawn-script to the ButtonPressed event of the Spawning-Button.

What do I need to do to connect the two together?

IMPORTANT: I am not speaking about Unity Buttons, but about an interactable getting assigned a Unityevent. I have yet to understand how this works

Salatgurke
  • 1,554
  • 1
  • 13
  • 35
  • Are you asking how to add an [onClick](https://docs.unity3d.com/530/Documentation/ScriptReference/UI.Button-onClick.html). It can be done in code or in the inspector – TEEBQNE Apr 20 '21 at 17:41
  • 2
    @TEEBQNE MRTK provides a type called [`Interactable`](https://learn.microsoft.com/windows/mixed-reality/mrtk-unity/features/ux-building-blocks/interactable) which works quite different to the `Button` component ;) It takes the HL2 articulated hands as input and is a 3D object with animations etc it still uses `UnityEvent` though of course – derHugo Apr 21 '21 at 06:25
  • 3
    OP maybe checkout [Interactable - Events](https://learn.microsoft.com/windows/mixed-reality/mrtk-unity/features/ux-building-blocks/interactable#events) – derHugo Apr 21 '21 at 06:29
  • Gotcha didn't know that. Good to know! – TEEBQNE Apr 21 '21 at 14:58

1 Answers1

0

Turns out I just needed to add the script function with the parameters I want to call to the "on press" event in the Button Events of that specific button. MRTK handles the rest.

Salatgurke
  • 1,554
  • 1
  • 13
  • 35