Snap to a position...

Hi. I am using this script to allow the player to freely move an object on the y axis. How can I make it so that the object will automatically snap to certain positions when the player lifts up their finger? For example, depending on which it is closest to, it will go to (0,2,0), (0,4,0), (0,6,0), etc.? Thanks

function Update()
{
   if(Input.touchCount == 1)
   {
      transform.position.y += Input.touches[0].deltaPosition.y*.1; 
   }
}

function Update()
{
if(Input.touchCount == 1)
{
transform.position.y += Input.touches[0].deltaPosition.y*.1;
transform.position.y = Mathf.Round(transform.position.y); // every one unit
}
}

To snap to other objects, yes, put them in an array, then you’ll ‘foreach’ through them, comparing distance to your dragged object, pick the closest, then set the position of the dragged object to the position of the nearest object. Or something like that.