public void AttachLeg(BodyJointBehaviour bodyPoint) { if (attachable && !attached) { leg.AttachLeg(bodyPoint); attached = true; attachable = false; body.attachedLegs.Add(this); attachmentPoint = bodyPoint; attachmentPointRb = attachmentPoint.GetComponent <Rigidbody2D>(); //attachmentPointJoint = GetComponent<SpringJoint2D>(); //attachmentPointJoint = attachmentPoint.GetComponent<SpringJoint2D>(); attachmentPointJoint.autoConfigureDistance = false; //attachmentPointJoint.connectedAnchor = new Vector2 (body.transform.InverseTransformPoint(bodyPoint.transform.position).x, body.transform.InverseTransformPoint(bodyPoint.transform.position).y); //attachmentPointJoint.autoConfigureConnectedAnchor = true; attachmentPointJoint.distance = springDistance; attachmentPointJoint.frequency = springFreq; attachCooldown = true; StartCoroutine(AttachCooldown()); //attachmentPointJoint.autoConfigureDistance = false; //attachmentPointJoint.distance = springDistance; //attachmentPointJoint.frequency = springFreq*6; //transform.position = attachmentPoint.transform.position; //hingeJoint.enabled = true; //hingeJoint.connectedBody = body.GetComponent<Rigidbody2D>(); // Move layers to avoid nasty collisions Transform[] _children = GetComponentsInChildren <Transform>(); foreach (Transform child in _children) { child.gameObject.layer = 8; } // play sound if (selected) { string randomAttachSound = "Attach_" + Random.Range(1, 4).ToString(); AudioManager.instance.Play(randomAttachSound); AudioManager.instance.ChangePitch(randomAttachSound, Random.Range(0.7f, 1.3f)); } // if first limb to attach, cue the music if (!GameManager.Instance.hasAttachedFirstLimb && selected) { GameManager.Instance.AttachedFirstLimb(); } Debug.Log("Foot Attached"); } }
public void AttachArm(BodyJointBehaviour bodyPoint) { if (attachable && !attached) { attached = true; attachable = false; attachmentPoint = bodyPoint; attachmentPointJoint = attachmentPoint.GetComponent <SpringJoint2D>(); transform.position = attachmentPoint.transform.position; fixedJoint.enabled = true; fixedJoint.connectedBody = body.GetComponent <Rigidbody2D>(); // Move layers to avoid nasty collisions Transform[] _children = GetComponentsInChildren <Transform>(); foreach (Transform child in _children) { child.gameObject.layer = 8; } Debug.Log("Arm attached"); } }