void OnCollisionEnter2D(Collision2D coll) { if (stamina == null) { stamina = player.StaminaBar.GetComponent<StaminaBarScript>(); } if (rb == null) { rb = GetComponent<Rigidbody2D>(); } if (stamina.Health > 0 && !stamina.Regening) { if (coll.gameObject.layer == 31) { float collisionForce = coll.rigidbody.velocity.magnitude; rb.AddForce(coll.relativeVelocity / stamina.Health * (isHead ? 1.5f : 1)); stamina.DecreaseBar(collisionForce / 5f * (isHead ? 1.5f : 1)); if (isHead || isLeftFoot || isLeftHand || isRightFoot || isRightHand && rb.velocity.magnitude > 10) { SoundManager.instance.PlaySound("Punch"); } } else { float collisionForce = rb.velocity.magnitude; if (collisionForce > 10f) { stamina.DecreaseBar(collisionForce / 5f * (isHead ? 1.5f : 1)); } player.touchingGround = true; if (isLeftFoot) { player.leftGrounded = true; } else if (isRightFoot) { player.rightGrounded = true; } } } }
void Start () { a = new GameObject(); SpriteRenderer Arender = a.AddComponent<SpriteRenderer>(); Arender.sprite = ATexture; Arender.sortingOrder = 100; a.transform.parent = transform; b = new GameObject(); SpriteRenderer Brender = b.AddComponent<SpriteRenderer>(); Brender.sprite = BTexture; Brender.sortingOrder = 100; b.transform.parent = transform; x = new GameObject(); SpriteRenderer Xrender = x.AddComponent<SpriteRenderer>(); Xrender.sprite = XTexture; Xrender.sortingOrder = 100; x.transform.parent = transform; y = new GameObject(); SpriteRenderer Yrender = y.AddComponent<SpriteRenderer>(); Yrender.sprite = YTexture; Yrender.sortingOrder = 100; y.transform.parent = transform; staminaBarScript = StaminaBar.GetComponent<StaminaBarScript>(); ragdoll = GetComponent<SkeletonRagdoll2D>(); ragdoll.Apply(); torso = ragdoll.GetRigidbody("Torso"); leftFoot = ragdoll.GetRigidbody("LeftFoot"); leftHand = ragdoll.GetRigidbody("LeftHand"); rightFoot = ragdoll.GetRigidbody("RightFoot"); rightHand = ragdoll.GetRigidbody("RightHand"); hip = ragdoll.GetRigidbody("Hip"); ragdoll.joints["LeftUpperArm"].limits = new JointAngleLimits2D() { min = -90, max = 90 }; ragdoll.joints["RightUpperArm"].limits = new JointAngleLimits2D() { min = -90, max = 90 }; ragdoll.joints["LeftLowerArm"].limits = new JointAngleLimits2D() { min = -100, max = 100 }; ragdoll.joints["RightLowerArm"].limits = new JointAngleLimits2D() { min = -100, max = 100 }; ragdoll.joints["LeftHand"].limits = new JointAngleLimits2D() { min = -30, max = 30 }; ragdoll.joints["RightHand"].limits = new JointAngleLimits2D() { min = -30, max = 30 }; ragdoll.joints["LeftShin"].limits = new JointAngleLimits2D() { min = -10, max = 10 }; ragdoll.joints["RightShin"].limits = new JointAngleLimits2D() { min = -10, max = 10 }; ragdoll.joints["LeftFoot"].limits = new JointAngleLimits2D() { min = -10, max = 10 }; ragdoll.joints["RightFoot"].limits = new JointAngleLimits2D() { min = -10, max = 10 }; }
// Update is called once per frame void Update() { //Debug.Log(Input.GetAxis("RightTrigger" + ((int)player.player).ToString()).ToString()); if (joint != null) { if (stamina == null) { stamina = player.StaminaBar.GetComponent<StaminaBarScript>(); } if (rb == null) { rb = GetComponent<Rigidbody2D>(); } if (stamina.Health == 0) { joint.connectedBody = null; joint.enabled = false; player.rightGrabbing = false; player.leftGrabbing = false; } if (joint.enabled == true && isLeftHand && Input.GetAxis("LeftTrigger" + ((int)player.player2).ToString()) <= .1f) { joint.connectedBody = null; joint.enabled = false; player.leftGrabbing = false; } if (joint.enabled == true && isRightHand && Input.GetAxis("RightTrigger" + ((int)player.player).ToString()) <= .1f) { joint.connectedBody = null; joint.enabled = false; player.rightGrabbing = false; } } }