- Home /
code to play my animation on button press, but it is looping. What do I add to stop this?
I've got a gun in my game to fire, and I've just created the animation for it. I setted up a code so that when I pressed down "fire" (LMB) that the animation would play. How ever it keeps on looping after I pressed it, which obviously is unideal. Here is the code (using Java)
var animation_bool : boolean ;
function Update()
{
if(animation_bool == true)
{
animation.Play("backfire");
}
if(Input.GetButtonDown("fire"))
{
animation_bool = true;
}
}
Answer by BeHappy · Sep 06, 2012 at 10:51 AM
Check this,
http://answers.unity3d.com/questions/45070/play-animation-only-once.html?sort=oldest
"Just use animation.Play() or animation.CrossFade() as usual but first set the wrapmode of your clip to WrapMode.Once. If you set the wrapmode in the inspector to "once" you don't need the first line."
animation["AnimationName"].wrapMode = WrapMode.Once;
animation.Play("AnimationName");
Your answer
Follow this Question
Related Questions
how can I trigger my animation through script? 1 Answer
Animating A pistol Firing 0 Answers
Trying to Make an Animation Work in Unity 5 0 Answers
Animation in unity 2 Answers