ridgidbody = false unless object is clicked with mouse

I was wondering if it is possible to give all ridgidbody objects the property ridgidbody = false, and activate their ridgidbody physics only if the user clicks them.

I borrowed some code which basically detects the object being clicked, but I still need to figure out how to set the ridgidbody objects to false and then activate them by hit.collider.name.

function Update()
{
    // ? ridgidbody = false ?
	//check if the left mouse has been pressed down this frame
	if (Input.GetMouseButtonDown(0))
	{
		//empty RaycastHit object which raycast puts the hit details into
		var hit : RaycastHit;
		//ray shooting out of the camera from where the mouse is
		var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		
		if (Physics.Raycast(ray, hit))
		{
			//print out the name if the raycast hits something
			Debug.Log(hit.collider.name);
			// *****************************************
			// Turn ridgid body on for this object only.
			// *****************************************     
		}
	}
}

Any ideas?

Thanks.

you cant really disable rigidbody

you can either not have a rigidbody on the objects and add the component, or you could put rigidbodies on the objects and check “is kinematic” in the inspector and then turn it off when you want physics

here is how you can add a rigidbody componant

if (Physics.Raycast(ray, hit))
       {

        //adds rigidbody component to object you hit
        hit.GameObject.AddComponent(Rigidbody); 

       }

the code to enable the rigidbody component is hit.rigidbody.enabled = true;
this is the equivalent to checking the checkbox next to rigidbody in the inspector view.

that being said this may not be what you want to do. If you just want to make it act like a normal rigidbody (reacting to forces and falling and such) then you should do this…

set isKinematic to true on the rigidbody when you want it to stay still, then when it is clicked do hit.rigidbody.isKinematic = false;