[SOLVED] Coroutine while loop exits before condition met

I’m at a loss as to why my coroutine doesn’t seem to be working. I’m trying to use MoveTowards to do a smooth translation of my character game object from one hex on the board to the next.
I also tried Lerp with the same results. Here’s the code:

private IEnumerator Walk()
    {
        fracDist = Vector3.Distance(transform.position, destination.transform.position);
        while (fracDist > 0.01f)
        {
            Debug.Log("HexUnit.Walk: Before distance = " + fracDist.ToString()
                + "

");
Vector3.MoveTowards(transform.position, destination.transform.position, Time.deltaTime * 1f);
fracDist = Vector3.Distance(transform.position, destination.transform.position);
Debug.Log("HexUnit.Walk: After distance = " + fracDist.ToString()
+ "
");
yield return null;
}
}

And here’s how I call it:

    public void MoveUnit()
        {
            princeAnimator.SetBool("moving", true);
            Debug.Log("HexUnit.MoveUnit: Starting to move

");
StartCoroutine(Walk());
Debug.Log("HexUnit.MoveUnit: Done moving
");
HaltUnit();
Location = destination;
}

The debug messages are as follows with identical timestamps:

HexUnit.MoveUnit: Starting to move

HexUnit.Walk: Before distance = 17.32051

HexUnit.Walk: After distance = 17.32051

HexUnit.MoveUnit: Done moving

HexUnit.Walk: Before distance = 17.32051

HexUnit.Walk: After distance = 0

HaltUnit() just tells the animator SetBool to go back to false.
When I comment out the “Location = destination;” line, I just get non-stop pairs of Before and After distance debug lines reflecting 17.32051. What am I doing wrong either in the while loop or in the MoveUnit() method where I call the coroutine? Thanks in advance.

Coroutines outlive the function that is calling them. This means that any code after the line StartCoroutine(Walk()); immediately runs, regardless of whether the coroutine has finished or not. You should call HaltUnit() in the coroutine, once the while loop has ended, because that’s when the player has reached its target. @Gone2Plaid