/// <summary> /// 检测范围并攻击 /// </summary> private void SlashAndDetect(CharacterAttack.AttackType attackType) { List <Collider2D> colliders = new List <Collider2D>(); attacker.Play(attackType, ref colliders); bool hasEnemy = false; bool hasDamageAll = false; // 检测是否攻击到敌人 foreach (Collider2D c in colliders) { if (c.gameObject.layer == LayerMask.NameToLayer("Enemy Detector")) { hasEnemy = true; break; } } // 检测是否攻击到陷阱 foreach (Collider2D c in colliders) { if (c.gameObject.layer == LayerMask.NameToLayer("Damage All")) { hasDamageAll = true; break; } } if (hasEnemy) { if (attackType == CharacterAttack.AttackType.DownSlash) { AddDownRecoilForce(); } else { StartCoroutine(AddRecoilForce()); } } if (hasDamageAll) { if (attackType == CharacterAttack.AttackType.DownSlash) { audioEffectPlayer.PlayOneShot(CharacterAudio.AudioClipType.SwordHitReject); AddDownRecoilForce(); } } foreach (Collider2D col in colliders) { Breakable breakable = col.GetComponent <Breakable>(); if (breakable != null) { breakable.Hurt(slashDamage, transform); } } }