using System.Collections.Generic; using UnityEngine; public class CastleMageSkill : UnitSkill { [Header("小型魔爆参数")] [Min(0.1f)] public float explosionRadius = 1.8f; [Min(0f)] public float explosionDamage = 85f; public override void ReleaseSkill() { GameObject target = unit.Target; UnitTeam myTeam = unit.GetComponent(); if (target == null || myTeam == null) { return; } Vector3 center = target.transform.position; float radiusSquared = explosionRadius * explosionRadius; HashSet hitUnits = new HashSet(); foreach (UnitTeam opponentTeam in GameObject.FindObjectsOfType()) { GameObject opponent = opponentTeam.gameObject; if (opponent == null || opponent.transform.root == unit.transform.root || !myTeam.IsEnemy(opponent)) { continue; } Vector3 offset = opponent.transform.position - center; offset.y = 0f; if (offset.sqrMagnitude > radiusSquared) { continue; } UnitBase targetUnit = opponent.GetComponentInParent(); if (targetUnit != null && hitUnits.Add(targetUnit)) { targetUnit.ReceiveDamage(explosionDamage, unit.gameObject); } } } }