Drag and drop certain rigid bodies

I want to create a script that allows me to drag and drop specific rigidbodies with the Tag Drag-able for example. i am using the DragRigidBody script from the Shadow Project on the unity site, but have no idea how to make it only drag the objects with the correct tag. any ideas?

Current Code:

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

var highlightMaterial : Material;
private var highlightObject : GameObject;

private var springJoint : SpringJoint;

function Update()
{
	var mainCamera = FindCamera();
	
	highlightObject = null;
	if( springJoint != null  springJoint.connectedBody != null )
	{
		highlightObject = springJoint.connectedBody.gameObject;
	}
	else
	{
		// We need to actually hit an object
		var hitt : RaycastHit;
		if( Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hitt, 100 ) ) {
			if( hitt.rigidbody  !hitt.rigidbody.isKinematic ) {
				highlightObject = hitt.rigidbody.gameObject;
			}
		}
	}
	
		
	// Make sure the user pressed the mouse down
	if (!Input.GetMouseButtonDown (0))
		return;

		
	// 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;
	}
	
	if (!springJoint)
	{
		var go = new GameObject("Rigidbody dragger");
		body = go.AddComponent ("Rigidbody");
		springJoint = go.AddComponent ("SpringJoint");
		body.isKinematic = true;
	}
	
	springJoint.transform.position = hit.point;
	if (attachToCenterOfMass)
	{
		var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
		anchor = springJoint.transform.InverseTransformPoint(anchor);
		springJoint.anchor = anchor;
	}
	else
	{
		springJoint.anchor = Vector3.zero;
	}
	
	springJoint.spring = spring;
	springJoint.damper = damper;
	springJoint.maxDistance = distance;
	springJoint.connectedBody = hit.rigidbody;
	
	DragObject(hit.distance, hit.point, mainCamera.ScreenPointToRay(Input.mousePosition).direction);
}

function DragObject (distance : float, hitpoint : Vector3, dir : Vector3)
{
	var startTime = Time.time;
	var mousePos = Input.mousePosition;
	
	
	var oldDrag = springJoint.connectedBody.drag;
	var oldAngularDrag = springJoint.connectedBody.angularDrag;
	springJoint.connectedBody.drag = drag;
	springJoint.connectedBody.angularDrag = angularDrag;
	var mainCamera = FindCamera();
	while (Input.GetMouseButton (0))
	{
		var ray = mainCamera.ScreenPointToRay (Input.mousePosition);
		springJoint.transform.position = ray.GetPoint(distance);
		yield;
	}
	
	if (Mathf.Abs(mousePos.x - Input.mousePosition.x) <= 2  Mathf.Abs(mousePos.y - Input.mousePosition.y) <= 2  Time.time - startTime < .2  springJoint.connectedBody)
	{
		dir.y = 0;
		dir.Normalize();
		springJoint.connectedBody.AddForceAtPosition(dir * pushForce, hitpoint, ForceMode.VelocityChange);
		ToggleLight( springJoint.connectedBody.gameObject );
	}	
	
	
	if (springJoint.connectedBody)
	{
		springJoint.connectedBody.drag = oldDrag;
		springJoint.connectedBody.angularDrag = oldAngularDrag;
		springJoint.connectedBody = null;
	}
}

static function ToggleLight( go : GameObject )
{		
	var theLight : Light = go.GetComponentInChildren(Light);
	if( !theLight )
		return;
		
	theLight.enabled = !theLight.enabled;
	var illumOn = theLight.enabled;
	var renderers = go.GetComponentsInChildren(MeshRenderer);
	for( var r : MeshRenderer in renderers )
	{
		if( r.gameObject.layer == 1 )
		{
			r.material.shader = Shader.Find(illumOn ? "Self-Illumin/Diffuse" : "Diffuse");
		}
	}
}

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

function OnPostRender()
{
	if( highlightObject == null )
		return;
		
	var go = highlightObject;
	highlightMaterial.SetPass( 0 );
	var meshes = go.GetComponentsInChildren(MeshFilter);
	for( var m : MeshFilter in meshes )
	{
		Graphics.DrawMeshNow( m.sharedMesh, m.transform.position, m.transform.rotation );
	}
}

If you add a script to the object(s) you want to select and drag, what you could do is just add a simple check.
For instance, if you add a script called DragableObject to the object, all you have to do is check if the object clicked has the DragableObject component. Adding this to your code should work:

...
var hitt : RaycastHit;
if( Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hitt, 100 ) ) {
	if(hitt.collider.gameObject.GetComponent("DragableObject") != null){
		highlightObject = hitt.rigidbody.gameObject;
	}
}
...

Now only those objects with the DragableObject script applied to them will be selected/available for dragging.

Thanks for the quick reply, i have added it to the script and created a script called DragableObject added that script to some objects but it did not seem to work. i got no errors but i can still drag any object with or without the DragableObject script attached

Managed to get it working using your code but adding it in a different place. i just added

if (hit.collider.gameObject.GetComponent("DragableObject") != null)
{
	
		return;
}

Thanks for the help!

Oops, you are right. With my method only those objects with the DragableObject script would be highlighted, but all the others could be dragged as well. For some reason I was just thinking about highlighting and not dragging. :stuck_out_tongue:
Glad you figured it out though!