how connect 2 object

hi all,
how to connect and disconnect the two objects using key.space and hingeJoint

or otherwise

Please help, I have no ideas :frowning:


from other question

how attach 2 object eg. tractor and trailer.

“hingeJoint.connectedBody” not work bcs trailer attach each side

var otherBody : Rigidbody;

function OnCollisionEnter (collision : Collision) {
    
    if (collision.rigidbody){
        hingeJoint.connectedBody = otherBody;
    	
        print("ho");
    }
}
function Update () {
    
     if (Input.GetKey(KeyCode.Z)){
    
    	hingeJoint.connectedBody = null;
        
    	print("hi");
    }
}

Ideas are here: http://unity3d.com/support/documentation/ScriptReference/Joint-connectedBody.html?from=HingeJoint

and

http://unity3d.com/support/documentation/ScriptReference/Input.GetKeyDown.html

ok how negate this ““hingeJoint.connectedBody = otherBody;””