How to make var equal a number from X to Y? 1m-5m?

How can I get the animation to play within a certain distance. As if, I want the model to “Walk” from 30m to 1m.

if (Distance < Encounter)

{

    animation.Play("WalkingTo")

}

var obj1pos : vector3 = obj1.transform.postion;
var obj2pos : Vector3= obj2.transform.postion;

var distance = Vector3.Distance(obj1pos,obj2pos);

if(distance > 1 || distance < 30) {play animation}

Try to use “Apply root motion” Animator’s flag properly.
Tutorial: Unity Connect