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.
Virtual button trigger animation
Attach the event handler to the VB's parent ImageTarget rather than the VB itself.
Virtual button trigger animation
That works DavidBeard thank you!
Virtual button trigger animation
hey, i copied the script that you posted, attached to the image target, then added the virtual button called green.
Virtual button trigger animation
Hi Adanete,
Did you named the button in the inspector pane green also? It took me a while before I saw that.
Virtual button trigger animation
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.
Virtual button trigger animation
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:
Virtual button trigger animation
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
Virtual button trigger animation
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:
Virtual button trigger animation
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