Can't Get Animation to Play Only One Time

(Huuuuge C# newbie, here)

When my character is close enough to an object (dice) and then clicks the object, an animation plays of the character grabbing the object.

The animation plays, but it loops and never ends. I just want it to play once and then stop.

This is the code I’ve added to the object that gets picked up:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DiceScript : MonoBehaviour {


    public bool GrabBool;
    public Animator PlayerAnimator;


    // Use this for initialization
    void Start () {
      
    }
  
    // Update is called once per frame
    void Update ()

    {
 
        if (Input.GetKey(KeyCode.Mouse0))

        {
      
        Collider[] hits = Physics.OverlapSphere (transform.position, 1);
        foreach (Collider hit in hits)

            {
                if (hit.tag == "Player") {
                  
                  
                    Destroy (gameObject);
                    PlayerAnimator.SetBool ("GrabBool", true);

                }
            }

        }          
    }

}



Everything works, except for the animation problem.
I’m going bonkers over here.

Thanks.

if you double click those animations in animator stage, there is loop option (its on by default i think)
4100017--358828--upload_2019-1-14_13-47-38.png

1 Like

Thanks for the reply.

As shown in image #3, LOOP TIME is unchecked.

I figured it out. I shouldn’t have been using a Bool. I needed to be using a Trigger.

But even if I was to use a bool, you need to deactivate the bool after activating it, in order to stop the animation.
Getting it to deactivate was a real pain. I never accomplished it.

Furthermore, “I was saying Bool-Erns”

1 Like

The reason that it restarts is because you transition from the Any State. That transition will be retriggered each time your animation has finished.