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