Translate 2 separate objects to each other's location

I have two cubes. One is on the left and the other on the right. I must click on both cubes in order to swap positions via translate. So far I have:

internal var selected : GameObject;

function Update () {
	if (Input.GetMouseButtonDown(0)) {
        var hit : RaycastHit;
        var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, hit)) {
        	if (hit.transform.gameObject.tag == "block") {
        		if (selected) {
        			if (selected != hit.transform.gameObject) {
        				hit.transform.Translate(selected.transform.position * Time.deltaTime);
        				selected.transform.Translate(hit.transform.position * Time.deltaTime);
        			}
        			selected = null;
        		} else {
	        		selected = hit.transform.gameObject;
	        	}
	        }
        }
    }
}

That didn’t work out for me. I also wanted to also control the speed of the swap too. Any idea?

You need to store the destinations first, then move each cube toward it’s target position over time, stopping when you’ve reached the goal.

In pseudocode, I’d expect my Update loop to look like this

if(!swapping)
{
	if(MouseClick)
	{
		swapping = true;
		LeftTarget = cube1.transform.position;
		RightTarget = cube2.transform.position;
	}
}
else
{
	fractionalTime = timeElapsed / desiredTranlateTime;
	cube2.transform.position = Lerp(cube2.transform.position, LeftTarget, fractionalTime);
	cube1.transform.position = Lerp(cube1.transform.position, RightTarget, fractionalTime);
	
	if(cube1.transform.position == RightTarget && cube2.tranform.position == LeftTarget)
	{
		swapping = false;
	}
}