I created new project and imported the virtualbutton unity package. Drag the ARCamera to Scene. ARCamera inspector Activated Loaddataset and drag the ImageTarget then assign the virtualbutton to child of ImageTarget. Drag the VirtualButtonEventHandler.cs script to ImageTarget. But my app is not working. Is i need to create button on image also? I wrote code in xml file for virtualButton. Is it enough?
- Sort Posts
- 8 replies
- Last post
virtual button is not working
I created virtual button with my own target and my own ImageTarget. How to do action with below code? If i want to open url means, is below code correct? But nothing happen. See the attached images.
Attachment | Size |
---|---|
![]() | 25.04 KB |
![]() | 159.19 KB |
virtual button is not working
I recommend that you start with the VB sample, import your own targets and replace the targets in the sample scene. You can then arrange the existing buttons as you need. Replace the existing VB event handlers on the ImageTargets with this one, which you can customize..
Name this script SimpleVBEventHandler.cs
using UnityEngine; public class SimpleVBEventHandler : MonoBehaviour, IVirtualButtonEventHandler { #region PUBLIC_METHODS /// <summary> /// Called when the virtual button has just been pressed: /// </summary> public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) { Debug.Log("OnButtonPressed for " + vb.name ); } /// <summary> /// Called when the virtual button has just been released: /// </summary> public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) { Debug.Log("OnButtonReleased for " + vb.name ); } #endregion // PUBLIC_METHODS #region UNTIY_MONOBEHAVIOUR_METHODS void Start() { // Register with the virtual buttons TrackableBehaviour VirtualButtonBehaviour vb = GetComponentInChildren<VirtualButtonBehaviour>(); if (vb) { vb.RegisterEventHandler(this); } } void Update() { } #endregion // UNTIY_MONOBEHAVIOUR_METHODS #region PRIVATE_METHODS #endregion // PRIVATE_METHODS }
.. you also may want to change the Sensitivity Setting on the VB's to HIGH for testing purposes.
Try that approach and tell me if you're still stuck.
virtual button is not working
David: Confusing me, I upload attached image to TargetManager, but the xml file doesn't have the buttons scale? why? This is the xml file:
Attachment | Size |
---|---|
![]() | 177.26 KB |
virtual button is not working
Is i need to create the button on image itself while upload to TargetManager. And, i didn't modify the wood target image xml file. But it's not working. See the attached images.
Attachment | Size |
---|---|
![]() | 206.35 KB |
![]() | 191.64 KB |
![]() | 183.03 KB |
virtual button is not working
You don't need to modify the XML when working in Unity. Be sure that your buttons are over features in the image - they won't work over a blank space. Also be aware that the very edge of the image isn't used for detection and so buttons won't work there either.
If that advice doesn't help, please post a screen grab of your expanded scene in Unity.
It's working. Thanks. How can i play audio for each button? Is i need to create AudioSource for each button?