Question by 
               fiterpilot · Sep 06, 2015 at 12:40 PM · 
                animationscripting problemanimationsscript error  
              
 
              On button down animation plays
I'm trying to make it so that when I push down a key, an animation will play. However I have been looking it up and trying to find a way to get that to work and everything I try has failed. Any help?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by sharat · Sep 06, 2015 at 12:53 PM
Add a custom component to trigger the animation.
 using UnityEngine;
 using System.Collections;
 
 public class MyAnimationHelper: MonoBehaviour {
 
     public Animation myAnim;
 
     void Update () {
         if (Input.GetKey (KeyCode.A)) {
             myAnim.Play();
         }
     }
 }
 
               For importing/creating the animation there are several ways to add one. I'd recommend checking out https://unity3d.com/learn/tutorials/topics/animation or any number of tutorial videos online for the type of animation you want.
Your answer