I can’t understand why I don’t want to work, Code (CSharp): public FixedJoint fxjoint; public Rigidbody woodGrab; void Start() { FixedJoint fxjoint = GetComponent<FixedJoint>(); } public void OnTriggerEnter(Collider other) { //if (other.tag == "Wood") fxjoint = gameObject.GetComponent<FixedJoint>(); fxjoint.connectedBody = woodGrab; }
What is it supposed to do? What is it doing that's wrong? Instead of gameObject.GetComponent<FixedJoint>();, did you meant to write other.gameObject.GetComponent<FixedJoint>();? That's just a guess because I don't know what your code is intended to do.
What do you mean "doesn't work"? Do you get an error message? I still haven't figured out what you wanted the code to do from your description. The code that you wrote will attach woodGrab to the object whenever the object touches any trigger collider. Did you want the object that has this code to be attached to the object that it collides with instead?