"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Virtual button trigger animation

Hello all,

 

I have a question about virtual buttons. I want to start an animation on my cube object.

Now I have this script:

using UnityEngine;

using System.Collections;

 

public class VirtualButtonHandler : MonoBehaviour, IVirtualButtonEventHandler{

 

    private GameObject cube;

 

// Use this for initialization

void Start () {

// Register with the virtual buttons TrackableBehaviour

        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();

        for (int i = 0; i < vbs.Length; ++i)

        {

            vbs[i].RegisterEventHandler(this);

        }

 

        // Get handle to the teapot object

        cube = GameObject.Find("cube").gameObject;

 

}

 

    // Called when the virtual button has just been pressed:

    public void OnButtonPressed(VirtualButtonBehaviour vb)

    {

        Debug.Log("OnButtonPressed");

 

        // Add the material corresponding to this virtual button

        // to the active material list:

        switch (vb.VirtualButtonName)

        {

            case "green":

                cube.animation.Play("Rotate180Degrees");

cube.animation.wrapMode = WrapMode.Once;

            break;

        }

    }

 

 

    // Called when the virtual button has just been released:

    public void OnButtonReleased(VirtualButtonBehaviour vb)

    {

 

        // Remove the material corresponding to this virtual button

        // from the active material list:

        switch (vb.VirtualButtonName)

        {

            case "green":

                //mActiveMaterials.Remove(m_TeapotMaterials[3]);

                break;

        }

    }

}

 

And dragged it onto the virtual button.

When I test the app the cube is displayed but the animation is not triggered when I push the virtual button.

Did I forget something or is the script not correct?

 

Thanks in advise.

DavidBeard

Mon, 07/09/2012 - 16:13

Yes confirm that the name is defined and also that your VB event handler is attached to the parent ImageTarget  - not the VB itself.

You'll also want to check within the event handler to confirm that the names correspond.

e.g.

the button is called green everywere and my structure is: 

-AR camera

-directional light

-imagetarget (virtualbuttoneventhandler)

 --element

 --Vbutton

it seems to be that the script is not correctly loading: 


DavidBeard

Tue, 07/10/2012 - 00:39

Had you once used a version of this script that did not derive from MonoBehaviour, or another script on ImageTargets that did not derive from MonoBehaviour?

That error is associated w/ a known Unity bug.

see: https://fogbugz.unity3d.com/default.asp?402166_um9ahlcplpdpe9bv

I dont know what are you talking about the mono behiavour.... i compiled 4 or 5 proyects using just animations but never with VB. 

the proyect runs but the button doesnt do anything, reimported everything but still the same notice... here are some specs:

 

If you look at the image below you see that I named the button in the inspector pane on two places at the top and at Virtual Button Behaviour (Script). That's important to get the button to work.

https://docs.google.com/file/d/0B-YKBtylPP4pdTJMd19LV2ZGM1k/edit