Why do my animations loop? (460470)

I’m having an animation start with the “animation.Play(animation)” but it keeps looping. I set my wrapmode from default to Once, but I can’t seem to get my animation to only play once. Anybody know what I might be missing?

I’ve also set the wrapmode to Once.

Thus far I have:

/////////Animation is already attached to the game object

function Update()
{
     if(talkTo  Input.GetKey("n"))
     {
          animation.Play("FaceManMove");
          talkTo = false;
     }
}

How do I get this to only play once?

try this

function Update()
{
     if(talkTo  Input.GetKey("n"))
     {
          animation.Play("FaceManMove");
          talkTo = false;
           if(talkTo == false){
                   animation.Stop();
              }
     }
}

However I may be wrong

I’m not sure I understand what you’re saying. If I put it in the Start() function nothing will ever happen if those two variables are true.

Is this what you’re talking about?

var talkTo = false;

function Start()
{
if(talkTo  Input.GetKey("n"))
{
animation.Play("anamation");
talkTo = false;
}
}

I dont know much about animations, but from what i read you want the animation to play when the player presses n, correct?

Yes. In the code I have above you’ll notice once N is press just once it won’t call that same code. So it should only play the animation just one time.

But for some reason it gets in a loop.

When the animation is done playing it restarts and never finishes unless I kill the engine.

try using GetKeyUp(“n”) see if that helps… also is ur animation set to play automatically? if that doesnt help i dunno whats wrong then

animation.Play( "animationName" );
animation.wrapMode  = WrapMode.Once;

This forces the animation to play once instead of wrapping (and how I’ve solved the same issue.) What I don’t get is why this is even necessary: the documentation states that animations are supposed to be in ‘WrapMode.Once’ by default.

When I play that “animation.wrapMode = WrapMode.Once;” Will that kill all the other animations attached to the object as well or just the one called out in animation.Play?

Use the Inspector to set the WrapMode per animation:

These animations weren’t imported though. They were created with Unity’s animation app.