Unity3d Need help to modify this scipt.

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;
   }
}

bump?

Your post was a little hard to understand, but I’m going to take a shot at this anyways and hope I correctly understand what your wanting to do.

If you don’t want it to make a joint unless ‘n’ is pressed, you could try copying the if statement on line 12 and put it just above, just below, or mixed (using between your conditionals) with line 4.

Yeah,i tried everything,same that way,i just need example or modification of my script,that would be awesome,cause my nerves are weak :smile: :smile:

put all the code in oncollisionenter inside an if(Input.GetKey(KeyCode.N)) (or whatever unity uses to see if a key is being pushed. Don’t use GetKeyDown here or it will only work on the update you push the key down.

However be warned you might like to pick different keys for join and unjoin.

I cant just put that script there,i need alot of modification,i dont understand what an where and again what to modify…