Script Doesn't work as intended

Ok, so I have this code that I’ve finally kinked all the bugs out of. But after all that the code doesn’t work exactly as intended.

firstly I have 3 “tiles” I want to be able to move by swapping it with an empty transform. But instead of them swapping the “tile” just moves over to the empty transform and the transform doesn’t move to allow for other “tiles” to switch to it.

Here’s the Code:

#pragma strict 

var Empty : Transform;
var Tile : GameObject;

function Start(){

Tile.transform.position.y = transform.position.y;
Tile.transform.position.x = transform.position.x;
Empty.transform.position = transform.position;
}

function OnMouseUp(){					
		if (Vector3.Distance(transform.position,Empty.position)==1){
		
		
		Tile.transform.position = Empty.transform.position;
		Empty.transform.position = Tile.transform.position;
		
		}

	}	

Any help would be awesome.

It looks like you are assigning the value in Empty to the Tile transform and then assigning the value in Tile back to Empty, which essentially does nothing other than overwrite what was originally in Tile. If you are trying to swap the two you should use an additional transform to store one of the values in the interim.

pseudocode:

temp = empty
empty = tile
tile = temp