Function is not updating the variable

Here is a very simple script in which when variable “move” is true, I want to move the gameobject to “target” location.

public class Truck : MonoBehaviour
{
    private bool move;
    Vector3 target;
    float closeProximityDistance = 1.0f;
    float speed = 1.0f;
    void Start()
    {
        move = false; }
    void Update()
    {
        if (move)
        {
            if (Vector3.Distance(this.transform.position, target) > closeProximityDistance)
            {
                transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * speed);
            }
            else
            {
                Debug.Log("Reached the position");
                move = false;
            }
        }
    }
    public void moveTo(Vector3 shopCoords)
    {
        target = shopCoords;
        move = true;
    }
}

moveTo() updates the ‘target’ and ‘move’ variables.
moveTo() function is being called from different script when any button is pressed. Also note that when that button is pressed, after that Truck gameobject is instantiated

The problem is game object doesn’t move because “move” is false even after the moveTo() is called. How to solve this?

,

I recommend that if you find your program is following a code path you don’t intend, use Debug.Log statements to check all the values being compared in the suspect if statement. Seeing values at the moment the strange behavior is occurring can often make it more apparent what is wrong. Let us know if that helps, hope it does!