While Instruction loop is executed once

HI
i am trying to make my snack walk forward while playing animation until it arrived to an game object.But every time my player enter in the trigger the snack x position increase once . this is my code

var Snack: GameObject;
var posFinal:Transform;
var posInitial:float;
var pasavance:float=5;
var isHere:boolean=false;
function Start()
{// save snack's first position
posInitial=Snack.transform.position.x;
}

function OnTriggerEnter( hit:Collider) 
{
    isHere=true;
}
function Update()
{
   if(isHere)
   {
Snack.animation.wrapMode = WrapMode.Loop;
do{
  // play animation walk
     Snack.animation.Play("Walk");
    // make snack move forward 
     Snack.transform.position.x+=pasavance;
           print(Snack.transform.position.x);
         }while(Snack.transform.position.x<posFinal.transform.position.x);
  isHere=false;
}

someone tell me what’s wrong please??

You have to remember that Update is called once per frame, but you are changing the Snack’s position multiple times in one frame until it is < posFinal. Only then do you return from Update and let Unity draw the frame. So you need to not even have a while loop inside Update. Just change your if to

if (IsHere && Snack.transform.position.x < posFinal.transform.postion.x)

Also, remove IsHere = false otherwise the next update won’t change the position either.