How can I drag an object along uneven terrain on its X and Y?

Hey, I'm looking for way to move buildings around, like in a RealTime Strategy, using a mouse drag. The thing is I want the buildings to follow the uneven terrain with the drag.

Thanks

You can cast a ray from the mouse screen coordinate until it hits the ground and when it hits the ground you get the position of the hit. Set the building to that position as long as it is hit.

You need to add a "terrain" tag to the terrain. There's probably an easier way but you get the point.

It might now work as is. I'm just trying to show you the idea of what you can do, implementation is up to you. cast a ray and get it's hit position if it hits an object tagged with "terrain" set the buildingObject to that position.

if(Input.GetMouseButton(0))
{
  var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  var hit : RaycastHit;
  if (Physics.Raycast (ray, hit, 1000) && hit.collider.gameObject.CompareTag("terrain")) {
    buildingObject.position = hit.position;
    //determin how much of the building needs to be moved down
    //i'll leave that up to you
  }
}