Untitled

mail@pastecode.io avatar
unknown
csharp
23 days ago
1.9 kB
2
Indexable
Never
  private void OnTriggerEnter2D(Collider2D collision)
  {
      //PARRYING  
      if (collision.tag == "EnemyWeapon")
      {
          if (collision.GetComponentInParent<Enemy>().attacking && isParrying && collision.GetComponentInParent<Enemy>().canReceiveParry)
          {
              weaponSource.PlayOneShot(parryClip);
              
              collision.GetComponentInParent<Enemy>().HandleReceivedParry();

              float distance = collision.transform.position.x - transform.position.x;
              if (distance > 0)
              {
                  collision.GetComponentInParent<Rigidbody2D>().AddForce(Vector2.right * 200, ForceMode2D.Impulse);
              }
              else
              {
                  collision.GetComponentInParent<Rigidbody2D>().AddForce(-Vector2.right * 200, ForceMode2D.Impulse);
              }
          }
      }

      if (collision.tag == "Enemy")
      {
          if (attackIsEffective && collision.GetComponent<Enemy>().canReceiveAttack)
          {
              Debug.Log("Hit");
              weaponSource.PlayOneShot(hitRobotClip);
              float distance = collision.transform.position.x - transform.position.x;
              if (distance > 0)
              {
                  collision.GetComponent<Rigidbody2D>().AddForce(Vector2.right * testHitForce, ForceMode2D.Impulse);
              }
              else
              {
                  collision.GetComponent<Rigidbody2D>().AddForce(-Vector2.right * testHitForce, ForceMode2D.Impulse);
              }
              
              collision.GetComponent<Enemy>().Kill();
              collision.GetComponent<Enemy>().canReceiveAttack = false;

          }
          
      }

      if (collision.tag == "Ground")
      {
          if (attackIsEffective)
              weaponSource.PlayOneShot(hitRobotClip);

      }
  }
Leave a Comment