i wanna make my button trigger an animation at an exact position

i wanna make my button be able to trigger an animation only when it is a meter away from an object
How will i do it

maybe it could be something like this:

    public Animator anim ;
    public void button()
    {
    if(meters < 10)
{
anim.SetBool("play animation", false);
}
    }

if you want to know more in-depth how you can play an animation in your code, or how to see how far away an object is, or what buttons are, that would be an entirely different discussion.