Want to move object slowly to where the mouse clicks?

I can move it instantly so far, and I also need to maintain level height (y=40)

if (Input.GetMouseButtonDown(0))
{
Plane plane = new Plane(Vector3.up, new Vector3(0, 40, 0));
Ray ray = 
Camera.main.ScreenPointToRay(Input.mousePosition);

if (plane.Raycast(ray, out float distance))
{
transform.position = ray.GetPoint(distance);
}
}

When you click, you want to store the position of the click in a variable. Let’s just call this

Vector3 clickPos.

So now:

 if (plane.Raycast(ray, out float distance))
 {
 clickPos = ray.GetPoint(distance);
 }

Now that we have our click position stored, we can move towards it in our Update loop.

void Update ()
{
    transform. position = Vector3.MoveTowards(transform.position, new Vector3(clickPos.x, 40, clickPos.z), moveDistance);
}