Пример #1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (myAttackCollider.IsTouchingLayers(LayerMask.GetMask("Player")) && collision.gameObject.tag == "EnemyDetectsPlayer")
     {
         GameObject         player       = collision.transform.parent.gameObject;
         PlayerController2D playerScript = player.GetComponent <PlayerController2D>();
         if (playerScript.knockbackTimer <= 0f && playerScript.isAlive)
         {
             playerScript.knockbackTimer = knockbackDuration;
             Vector2 dir = (player.transform.position - this.transform.position);
             float   horizontalKnockback = horizontalKnockBackIntensity * dir.normalized.x;
             player.GetComponent <Rigidbody2D>().velocity = new Vector2(horizontalKnockback, verticalKnockBackIntensity);
             playerScript.TakeDamage(damage);
         }
     }
     XCollisionEnter(collision);
 }