53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
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;
|
|
if (target == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string opponentTag = unit.OpponentTag;
|
|
if (string.IsNullOrEmpty(opponentTag))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector3 center = target.transform.position;
|
|
float radiusSquared = explosionRadius * explosionRadius;
|
|
HashSet<UnitBase> hitUnits = new HashSet<UnitBase>();
|
|
|
|
foreach (GameObject opponent in GameObject.FindGameObjectsWithTag(opponentTag))
|
|
{
|
|
if (opponent == null || opponent.transform.root == unit.transform.root)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Vector3 offset = opponent.transform.position - center;
|
|
offset.y = 0f;
|
|
if (offset.sqrMagnitude > radiusSquared)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
UnitBase targetUnit = opponent.GetComponentInParent<UnitBase>();
|
|
if (targetUnit != null && hitUnits.Add(targetUnit))
|
|
{
|
|
targetUnit.ReceiveDamage(explosionDamage, unit.gameObject);
|
|
}
|
|
}
|
|
}
|
|
}
|