Problem with boolean

Hi everybody,
I can not put together a scipt, where bool say go to the point until you hit it, then set false.
I enclose the script that is not working (I must hold the mouseButton down for a while, to get the player to that position. What I want is only one click and the player go to the point where was clicked automatically:

public GameObject player;
private Ray ray;
private RaycastHit rayCastHit;
private bool moveTo;
private float moveSpeed = 100;

void Update(){
if (Input.GetMouseButton(0)){

			ray = Camera.main.ScreenPointToRay (Input.mousePosition);
			
			if (Physics.Raycast (ray, out rayCastHit)) {
				moveTo = true;
				if(moveTo)
				{
					Vector3 position = Vector3.MoveTowards(transform.position, rayCastHit.point, moveSpeed * Time.deltaTime);
    				position.z = 0;
    				transform.position = position;
				}
			}
}
		if(transform.position == rayCastHit.point)
		{
			moveTo = false;
		}
}

it is working, when I put the following lines together at the ende of the Update method. But the Vector3 position is outside the if (Input.GetMouseButton (0)) and has diffrent outcome with the player. Is there any other way to get it workin?? Thank for any help.

if(moveTo)
{
    Vector3 position = Vector3.MoveTowards(transform.position,    rayCastHit.point, moveSpeed * Time.deltaTime);
    position.z = 0;
    ransform.position = position;
       if(transform.position == rayCastHit.point)
             {
                 moveTo = false;
             }
}

Please note: I have not tested this, it is merely intended to show you how I would structure the logic, and where I would declare the variables.

bool moveTo;
Vector3 moveToPos;
float moveSpeed;
void Update () {
	if (Input.GetMouseButton(0)){
		Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
		RaycastHit rayCastHit=new RaycastHit();
		if (Physics.Raycast (ray, out rayCastHit)) // this will check to see if you are clicking a GameObject
		{
			moveTo = true;
			moveToPos = rayCastHit.point;
		}
	}
	if(transform.position == moveToPos)// at destination? BEWARE: we are not checking to see if we have moved PAST the destination between calls to Update()
	{
		moveTo = false;
	}
	if(moveTo)//are we still moving?
	{
		Vector3 position = Vector3.MoveTowards(transform.position, moveToPos, moveSpeed * Time.deltaTime);
		position.z = 0;
		transform.position = position;
	}
}