- Home /
how do i stop an animation looping?
I want to make a first person game where you swing a sword. I've made the animation for the sword swinging but when I press play it automatically starts looping. this is my code:
'#pragma strict
function Update () { if(Input.GetMouseButton(0)){ animation.Play("Attack_001"); } else{ animation.Stop("Attack_001"); } }'
How can I make it so that it only loops when I hold down left click?
P.S. sorry, i'm kinda a noob to unity.
Answer by Owen-Reynolds · Dec 24, 2013 at 03:17 PM
Find the animation (Attack_001) in the Assets (Project) folder. Unloop it there.
Depending on how it was made, uncheck the Loop box, or switch WrapMode to PlayOnce (it should be obvious, once you're there.) Check Apply when done (but it will usually ask anyway.)
A funny thing about animations is they are "smart," and won't restart playing if they already are. So you can safely use animation.Play
every frame (or CrossFade, which avoids little jumps) to get a "loop while held down."
Answer by Ethan_John · Jul 15, 2021 at 05:14 PM
Open the animation file in your assets folder, and disable 'Loop time'
Your answer
![](https://koobas.hobune.stream/wayback/20220613124812im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity3D Destroying animation after its played 1 Answer
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Animation problems... 1 Answer