Ejemplo n.º 1
0
    void Attack()
    {
        isAttackPressed = true;

        Collider2D target = Physics2D.OverlapCircle(attackPoint.position, attackRange, enemyLayers);
        EnemyHP    enemy  = null;

        try
        {
            enemy = target.GetComponent <EnemyHP>();
        }
        catch { }
        if (enemy != null)
        {
            enemy.GetComponent <EnemyHP>().TakeDamage(damage);
            DamageIndicator.Create(enemy.transform.position, damage);
            int    attackIndex = Random.Range(1, 4);
            string soundClip   = string.Concat("Swidle", attackIndex.ToString());
            FindObjectOfType <AudioManager>().Play(soundClip);
        }
        else
        {
            int    attackIndex = Random.Range(1, 4);
            string soundClip   = string.Concat("Swidle", attackIndex.ToString());
            FindObjectOfType <AudioManager>().Play(soundClip);
        }
    }