void OnTriggerStay2D(Collider2D collider) { HurtBox hurtBox = collider.gameObject.GetComponentInParent <HurtBox>(); Animator hurtCharAnimator = collider.gameObject.GetComponentInParent <Animator>(); Projectile otherProjectile = collider.gameObject.GetComponent <Projectile>(); if (otherProjectile || collider.gameObject.GetComponent <Ground>() && !animator.GetBool("madeContact")) { CountNumHits(); physicsBody.velocity = new Vector2(0f, 0f); } else if (hurtBox && hurtBox.gameObject.tag != gameObject.tag && !hurtBox.GetHurtBoxCollided() && !animator.GetBool("madeContact")) { CountNumHits(); hurtBox.SetHurtBoxCollided(true); Character hurtCharacter = hurtBox.GetComponentInParent <Character>(); Rigidbody2D hurtPhysicsbody = hurtCharacter.GetComponent <Rigidbody2D>(); if (hurtCharacter.GetBackPressed() == true && hurtCharAnimator.GetBool("isAttacking") == false && hurtCharAnimator.GetBool("isLiftingOff") == false && hurtCharAnimator.GetBool("isAirborne") == false && hurtCharAnimator.GetBool("isInHitStun") == false) { //if attack is blocked if ((moveType == MoveType.low && hurtCharAnimator.GetBool("isCrouching") == false) || (moveType == MoveType.mid && hurtCharAnimator.GetBool("isStanding") == false)) { ProjectileLanded(hurtCharAnimator, hurtCharacter, hurtPhysicsbody); } else { ProjectileBlocked(hurtCharAnimator, hurtCharacter, hurtPhysicsbody); } } else { ProjectileLanded(hurtCharAnimator, hurtCharacter, hurtPhysicsbody); } hurtCharacter.GetSuper += 1.5f; } }
void OnTriggerStay2D(Collider2D collider) { HurtBox hurtBox = collider.gameObject.GetComponentInParent <HurtBox>(); Animator hurtCharAnim = collider.gameObject.GetComponentInParent <Animator>(); // Vector2 hitLocaterStart, hitLocaterEnd; if (hurtBox && !hurtBox.GetHurtBoxCollided()) { hurtBox.SetHurtBoxCollided(true); cancellable = true; TimeControl.slowDown = true; Character hitCharacter = gameObject.GetComponentInParent <Character>(); Character hurtCharacter = hurtBox.GetComponentInParent <Character>(); Animator hitCharAnim = gameObject.GetComponentInParent <Animator>(); Rigidbody2D hurtPhysicsbody = hurtCharacter.GetComponent <Rigidbody2D>(); Rigidbody2D hitPhysicsbody = hitCharacter.GetComponent <Rigidbody2D>(); //hit spark effect //grab the collider components BoxCollider2D hurtCollider = collider.gameObject.GetComponent <BoxCollider2D>(); BoxCollider2D hitCollider = gameObject.GetComponent <BoxCollider2D>(); //find center // if (hitCharacter.side == Character.Side.P1){ // hitLocaterStart = new Vector2(hurtCollider.bounds.min.x, hurtCollider.bounds.min.y); // hitLocaterEnd = new Vector2(hitCollider.bounds.max.x, hitCollider.bounds.max.y); // } // else{ // hitLocaterStart = new Vector2(hurtCollider.bounds.max.x, hurtCollider.bounds.max.y); // hitLocaterEnd = new Vector2(hitCollider.bounds.min.x, hitCollider.bounds.min.y); // } Vector2 hitLocaterStart = new Vector2(hurtBox.transform.position.x, hurtBox.transform.position.y); Vector2 hitLocaterEnd = new Vector2(transform.position.x, transform.position.y); //cast a raycast line that locates the spark effect RaycastHit2D sparkLocation = Physics2D.Raycast(hitLocaterStart, hitLocaterEnd); Vector3 sparkEffect = new Vector3(sparkLocation.transform.position.x, sparkLocation.transform.position.y, 0f); leftEdgeDistance = Mathf.Abs(CameraControl.leftBGEdge) + hurtCharacter.transform.position.x; rightEdgeDistance = CameraControl.rightBGEdge - hurtCharacter.transform.position.x; distance = hurtCharacter.transform.position.x - hitCharacter.transform.position.x; if (hitCharacter.GetHasntHit() == true) { if (hurtCharAnim.GetBool("isAirborne") == false) { if (hurtCharacter.GetBackPressed() == true && hurtCharAnim.GetBool("isAttacking") == false && hurtCharAnim.GetBool("isLiftingOff") == false && hurtCharAnim.GetBool("isInHitStun") == false && hurtCharAnim.GetBool("isKnockedDown") == false && hurtCharAnim.GetBool("isLanding") == false) { if ((hitCharacter.GetMoveType() == Character.MoveType.low && hurtCharAnim.GetBool("isCrouching") == false) || (hitCharacter.GetMoveType() == Character.MoveType.mid && hurtCharAnim.GetBool("isStanding") == false)) { //if blocked high, but got hit by a low attack //or if blocked low, but got hit by an overhead(jumping attacks only) InHitStun(hitCharacter, hurtCharacter, hurtCharAnim, hitCharAnim, sparkEffect, hurtPhysicsbody, hitPhysicsbody); } else { //successful block InBlockStun(hitCharacter, hurtCharAnim, hitCharAnim, hurtPhysicsbody, hitPhysicsbody, sparkEffect); } } else { //hit everytime with no block attempt InHitStun(hitCharacter, hurtCharacter, hurtCharAnim, hitCharAnim, sparkEffect, hurtPhysicsbody, hitPhysicsbody); } } else { //there's no blocking in this game when you're airborne like in normal street fighter alphas, because i said so InHitStun(hitCharacter, hurtCharacter, hurtCharAnim, hitCharAnim, sparkEffect, hurtPhysicsbody, hitPhysicsbody); } hurtCharacter.GetSuper += 1.5f; hitCharacter.GetSuper += hitCharacter.GetSuperAccumulated(); hitCharAnim.SetBool("hasntHit", false); } } }