How to get an animation to play when a character walks up to an object?

I would like to make a short pull out animation play when the character walks in a certain area, but I would like it to only play once. I’ve already made the animation, I just don’t know how to program it so that it only plays once and only plays when a character walks to a certain place. Can anyone help :frowning: I use C#

is simple just have to put two animations,
a static that will be the first that will do nothing
and one that will make the animation you want.
then you put the animator Hits from one to another with one parameter “say boolean”, if true enters the animation you want, if false out of it.
also that when you finish return back to the static animation

click right to the last part of the animation you want to reprdusca only once, is that I’m wrong animation so I put the white box :v

then the script c # you put something like this:
public Animator anin;

    //when entering a collider and the player has the tag of Player
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            anin.SetBool("ini", true);
        }
    }
    //-------------------------------------------------------------

    //when you leave the collider, the Player
    void OnTriggerExit(Collider other)
    {
        if (other.tag == "Player")
        {
            anin.SetBool("ini", false);
        }
    }
    //------------------------------------------------------------



    //when you want to end the animation is returned to the "static"
    public void GiveBack()
    {
        anin.SetBool("ini", false);
    }
    //--------------------------------------------------------------