restrict drag within screen

got this script from this site
var screenPoint;
var offset;

function Update () {
}
function OnMouseDown() { scanPos= gameObject.transform.position; screenPoint = Camera.main.WorldToScreenPoint(scanPos); offset = scanPos - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); }

function OnMouseDrag() { curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset; transform.position = curPosition; }

how to restrict the object within the screen?

Go to this Page link text. There is a great tutorial here as well as the code. This will solve your problem.

Good Luck!