Esempio n. 1
0
 public void DoAttackMelee()
 {
     if (isReadyToAtack)
     {
         isReadyToAtack     = false;
         doAtk              = true;
         lastTargetPosition = target.position;
         Vector2 dir = lastTargetPosition - transform.position;
         Debug.DrawRay(transform.position, dir, Color.red, 2f);
         int          layer = 1 << 10;
         RaycastHit2D hit   = Physics2D.Raycast(transform.position, dir, 1, layer);
         if (hit)
         {
             if (hit.collider.tag == "Player")
             {
                 PlayerKnightController player = hit.transform.GetComponent <PlayerKnightController>();
                 player.RecieveDamage(atkDamage);
             }
         }
     }
 }
Esempio n. 2
0
 public void DoExplosion()
 {
     if (isReadyToAtack)
     {
         isReadyToAtack     = false;
         doAtk              = true;
         lastTargetPosition = target.position;
         Vector2      dir   = lastTargetPosition - transform.position;
         int          layer = 1 << 10;
         RaycastHit2D hit   = Physics2D.CircleCast(transform.position, explosionRadius, dir, explosionRadius, layer);
         if (hit)
         {
             if (hit.collider.tag == "Player")
             {
                 PlayerKnightController player = hit.transform.GetComponent <PlayerKnightController>();
                 player.RecieveDamage(atkDamage);
             }
         }
         myAnimator.SetTrigger("Explosion");
         audioSource.PlayOneShot(explosionClip);
     }
 }