Is that you want to move the object in grid but it cannot move to its starting position? If so, I had made some modifications based on your script, you may test it out to see whether it can help you or not.
#pragma strict
private var startPos : Vector3;
private var targetPos : Vector3;
function Start ()
{
// Record the startPos
startPos = transform.position;
}
function Update()
{
// Set targetPos as the transform's current position
targetPos = transform.position;
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
targetPos.x -= 1;
}
else if (Input.GetKeyDown(KeyCode.RightArrow))
{
targetPos.x += 1;
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
targetPos.y += 1;
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
targetPos.y -= 1;
}
// Set transform at targetPos if it is not startPos
if (targetPos != startPos)
{
transform.position = targetPos;
}
}