Vuforia (AR) Play animation on Target Image found (SCRIPT Help)
I need help with scripting to play the animation on Image Target found. I have my animation as a child of the Image Target and I'm editing the Default TrackableEventHandler script that comes with Vuforia.
This tweak will autoplay the animation.
private void OnTrackingFound()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
Collider[] colliderComponents = GetComponentsInChildren<Collider>();
Animator[] animatorComponents = GetComponentsInChildren<Animator>(); // I have added this
foreach (Animator anim in animatorComponents) {
anim.Play("Take 001", -1, 0f);
Debug.Log ("***anim component: " + anim.name);
}
// Enable rendering:
foreach (Renderer component in rendererComponents) {
if (component.name != "Video" && component.name != "Icon"){
component.enabled = true;
}
}
// Enable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
}
private void OnTrackingLost()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
// Disable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = false;
}
// Disable colliders:
foreach (Collider component in colliderComponents)
{
component.enabled = false;
}
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
}
Then if I add this:
private void OnTrackingLost()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
Animator[] animatorComponents = GetComponentsInChildren<Animator>(true);
// Disable Animator:
foreach (Animator component in animatorComponents)
{
component.enabled = false;
}
It won't play the animation at all. I've been scouring the internet for a week now and everything is using old scripting before the Animator using legacy animation. Can someone please help me. I'm going insane. You think this would be one of the main items that they would document but nope. I check out the Vuforia sample project and they didn't contain any animation clips on their objects.
As for the animation. I have it attached to gameObject as a child of the ImageTarget with an "idle" state set as default in the Animator with no transition to my animation clip.
Please help me. Please.
Vuforia 6.2 + Unity 5.6
Your answer
Follow this Question
Related Questions
ANIMATION STRANGELY DOES NOT PLAY 0 Answers
Animation triggered by other animation, script, c# 1 Answer
Help with a door slam trap 0 Answers
Flipping Animation/Jumping animation 0 Answers
Animator Position VS Script Vector 3 0 Answers