draging a object

I have apple tree in my game with lots apple around its branches.i tried the drag rigid body script to drag the apple it is not working for me .I want the player should drag and drop the apple from the tree in to the basket kept in the right hand side of the screen.I want the player should only exactly drag and drop the apple into the basket he should not be able to drag and drop the apple another than basket after plucking from the apple tree by drag and drop.He try to drop other than basket it should move with mouse point as long as he drop into the basket.i tried a lots of ways not working for me.All helps are welcomed

You should set the apple tag to “apple”, cast a ray from the mouse pointer and check if some object tagged “apple” was hit. If so, save the object transform in a variable and make it follow the mouse pointer until the mouse button is released AND the apple is over the basket. When this happens, add a rigidbody to the apple, let it fall by gravity and clear the variable until another apple is picked.

The script below does this; it requires the apples to be tagged “apple” and have no rigidbody. The simplest way is to make the basket a trigger, and in OnTriggerEnter add points and destroy the fallen apples. If this can’t be done, the basket must have walls to contain the apples, or they will roll to all sides when falling over the basket.

var basket: Transform;  // drag basket object here
var basketWidth: float = 2;  // set basket internal width

private var apple: Transform = null;  // reference to the apple picked
private var ray: Ray;
private var hit: RaycastHit;
private var plane: Plane;

function Update(){

    if (!apple){ // if no apple picked
		if (Input.GetMouseButton(0)){  // and left button pressed
			ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			if (Physics.Raycast(ray, hit) && hit.transform.tag=="apple"){
				apple = hit.transform;  // this is the apple to move
				// create a vertical plane passing through apple and basket
				plane = Plane(apple.position, basket.position, basket.position+Vector3.up);
			}
		}
	} else {
		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		var length: float;
		plane.Raycast(ray, length);
		if (length < 0) length = -length;
		apple.position = ray.GetPoint(length);  // apple follow mouse pointer on the plane
		if (!Input.GetMouseButton(0)){
			var distance = apple.position - basket.position;
			distance.y = 0;  // ignore height difference
			if (distance.magnitude <= basketWidth/2){ // if over the basket...
				apple.gameObject.AddComponent(Rigidbody);  // add rigidbody to apple
				apple = null;  // and abandon the apple
			}
		}
	}
}