Playing around with the drag script

Hi there

So I’ve been playing around with the drag and drop script.

and I all most got it to do what I want.

so what it does right now is. it castes a ray no the object I select with the mouse, identifies where my Player is and throws the object that way.

What I want it to do is, Destroy when it hits the player (the selected object) how do I identify that object??

var spring = 50.0;
var damper = 5.0;
var drag = 10.0;
var angularDrag = 5.0;
var distance = 0.2;
var attachToCenterOfMass = false;


private var springJoint : SpringJoint;

function Update ()
{
	// Make sure the user pressed the mouse down
	if (!Input.GetMouseButtonDown (0))
		return;

	var mainCamera = FindCamera();
		
	// We need to actually hit an object
	var hit : RaycastHit;
	if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hit, 100))
		return;
		
	// We need to hit a rigidbody that is not kinematic
	if (!hit.rigidbody || hit.rigidbody.isKinematic)
		return;

	//What????
	if (!springJoint)
	{
		var go = new GameObject("Rigidbody dragger");
		body = go.AddComponent ("Rigidbody");
		springJoint = go.AddComponent ("SpringJoint");
		body.isKinematic = true;
	}
	
	springJoint.transform.position = hit.point;
	
	//What??
	if (attachToCenterOfMass)
	{
	
		var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
		anchor = springJoint.transform.InverseTransformPoint(anchor);
		springJoint.anchor = anchor;
	}
	
	
	else
	{
	
		var Player = GameObject.Find("player");
	    var playerpos = Player.transform.position;
		
		springJoint.anchor = Vector3.zero;
		springJoint.transform.position = playerpos;
		
	}
	
	springJoint.spring = spring;
	springJoint.damper = damper;
	springJoint.maxDistance = distance;
	springJoint.connectedBody = hit.rigidbody;


}
function FindCamera ()
{
	if (camera)
		return camera;
	else
		return Camera.main;
}

Hope you can help me

Bo

You can detect when a rigidbody object hits another collider by adding an OnCollisionEnter function to its script. The Collision object passed in as a parameter contains fields for the transform, game object, rigidbody and collider of the the object that was hit. You just need to compare one of these with the player to see if they are equal:-

if (other.transform == player.transform) {
    Destroy(other.gameObject);
}

But while trying to destroy i get the following error. Please let me know how i could get this part working to destroy the object just on click of another Oject.

Thnaks in Advance.