Animation Loop When Button Held Down

Hi There,
I have been having trouble getting my animation to loop when “w” key is held down. I was wondering if anyone would be able to help me out because I’m kind of a “noob” :slight_smile:
Thanks In Advance,
Dan

Use this JavaScript

var keyForLooping = "w";
var animationToLoop : String; //Insert the name of the animation you wish to loop

function Update () {
    if(Input.GetKey(keyForLooping)) {
        animation[animationToLoop].wrapMode = WrapMode.Loop;
        if(!animation.IsPlaying) { //This is to see if the animation finished while the key was up
            animation.Play(animationToLoop);
        }
    } else {
        animation[animationToLoop].wrapMode = WrapMode.Once;
    }
}

Hope this is what you meant :slight_smile:

~ExplodingCookie