Hinge Joint Script doesn't work..

First of all hi everybody and this is the question: I want to make a hinge joint between two rigidbodies and wrote this code. But unfortunately it did not work. My main goal is making this hinge joint while Collision Enter and pressing a keyboard key at the same time. But i can not do this without the hinge joint working first. Here is the code:

`

using UnityEngine;

using System.Collections;

public class attachcontrol : MonoBehaviour {

public Rigidbody myobj;

void AttachControl() {

hingeJoint.connectedBody = myobj;

hingeJoint.anchor = new Vector3(0.008575243f, -0.08854485f, -1.658814f);

} }`

function OnCollisionEnter (hit : Collision){

}