Play a simple animation once on key press

I’m experimenting with controlling a little robot player that has an animation to make himself get taller (kind of like a jumping motion). I have saved the animation and it works find when the Animator component loops it through continuously. I would like to instead play this short animation once, until it finishes, on (Input.GetKey(KeyCode.UpArrow)) - is this possible? PS Javascript would be ideal as I’m a beginner :slight_smile: Thanks!

Add a flag, so on keypress change isPlaying = true; so that other times you press up it won’t reset the animation.

Yes, it is, something like this should do:

 animation["YourAnimation"].wrapMode = WrapMode.Once;
        ...
    void Update()
    {
        if ( Input.GetKey(KeyCode.UpArrow) )
        {
           StartCoroutine(PlayAnimation()); 
        }
    }
        ...
    IEnumerator PlayAnimation()
    {
           animation.CrossFade("YourAnimation");
           animation.Play("YourAnimation");
           yield WaitForSeconds (animation["YourAnimation"].length);
    }

When the animation file is clicked, there’s an option to uncheck the ‘Loop Time’ in the Inspector window. That will do it, I think.