MM77
MM77

Reputation: 113

How can i instantiate Vuforia's virtual button and assign a handler to it?

I am currently working on a project that requires creating virtual buttons while the app is running and naturally assign an event handler to it to detect it being pressed/released.

I have tried all the solutions i found on Vuforia's forums and stackoverflow but the virtual buttons never worked. They get instantiated and a clone is made like I want but apparently the event handler is not assigned properly.

So my question is, is it even possible to create a virtual button after the app starts and assign a handler to it?

Upvotes: 0

Views: 695

Answers (2)

MM77
MM77

Reputation: 113

After too much research, I found out that creating custom virtual buttons after the beginning of tracking is not possible using the current Vuforia version.

The alternative I found is creating a unity gameObject (Cube in my case) with a box collider and a tag that could be pressed through the mobile screen of the app and using raycasting.

Would welcome answering any questions you have.

Upvotes: 0

Everts
Everts

Reputation: 10701

Either the button is a GUI button then, it would be a basic UI button from the uGUI framework from Unity:

https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button

The second is a button that is position in the scene, most likely along the model that you show on tracker found.

In this case, either use a world canvas button, similar to the previous one but with a world canvas or use a quad/box object and use a basic raycast as you would do in a normal game.

If you need them to show on track found, set them on and off just like you do with the model by listening to the OnTrackFound/Lost.

To register listener, it is explained in the video.

Upvotes: 1

Related Questions