Search code examples
unity-game-enginehololensmrtk

How can I spawn and delete GameObjects via Buttons dynamically at Runtime using MRTK in Unity?


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


Solution

  • 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.