I want to Play Animation when Virtual Button Pressed using Unity & Vuforia. But i don't know why i got an error "there is no 'Animation' attached to the game object"
I'm using Unity 4.7.0 and Vuforia 5-0-10
This is the code that attached to the ImageTarget
using UnityEngine;
using System.Collections;
public class VBEventHandler : MonoBehaviour, Vuforia.IVirtualButtonEventHandler {
public GameObject person;
void Start(){
Vuforia.VirtualButtonBehaviour[] vbs = GetComponentsInChildren<Vuforia.VirtualButtonBehaviour> ();
for(int i=0; i<vbs.Length; i++){
vbs[i].RegisterEventHandler(this);
}
person = transform.FindChild("person").gameObject;
}
public void OnButtonPressed(Vuforia.VirtualButtonAbstractBehaviour vb){
switch (vb.VirtualButtonName) {
case "VBAnim":
person.animation.Play();
break;
}
}
public void OnButtonReleased(Vuforia.VirtualButtonAbstractBehaviour vb){
switch (vb.VirtualButtonName){
case "VBAnim":
person.animation.Stop();
break;
}
}
}
am I missing something?
Note that the error says
there is no 'Animation' attached to the game object
I'm thinking, it is very likely that
there is no 'Animation' attached to the game object
What you should do is check if
there is no 'Animation' attached to the game object
You may find that
there is no 'Animation' attached to the game object
If it turns out
there is no 'Animation' attached to the game object
then you've discovered the problem you're having,
there is no 'Animation' attached to the game object
Heh! It's that easy.
Setting aside the humor, do note that these days
You attach an Animator
. You don't, really, use animations directly.
Review basic tutorials on animating humanoids in Unity. ( UMotion is highly recommended when working with animation in Unity.)