- Home /
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" :) Thanks In Advance, Dan
Comment
Please post your script in the question, otherwise we don't know what you did wrong.
Answer by ExplodingCookie · Jul 06, 2013 at 06:55 PM
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 :)
~ExplodingCookie