Hello,this script makes objects stick to any collision…When game starts it creates connection between collision and if i press “n” it breaks that connection and again when i touch collision (same thing…) Well what i want to do is : Only when i press “n” THEN it creates connection and i have to walk up to any collision and its gonna stick to that,not at game start but only when i press “n” it makes connection and when i press “n” again it breaks connection.I were messing up with this and i think its impossible :? So,do you have any ideas? Help?
Script:
var jointExist : boolean;
function OnCollisionEnter(c : Collision) {
if(!jointExist){
var joint = gameObject.AddComponent(FixedJoint);
joint.connectedBody = c.rigidbody;
jointExist = true;
}
}
function Update(){
if(Input.GetKeyDown(KeyCode.N)){
var joint = gameObject.GetComponent(FixedJoint);
Destroy(joint);
jointExist = false;
}
}