using UnityEngine; public class ArcherHunterSkill : UnitSkill { [Min(0f)] public float splitShotRadius = 3f; public override void ReleaseSkill() { GameObject mainTarget = unit.Target; if (mainTarget == null) { return; } GameObject nearbyOpponent = FindNearbyOpponent(mainTarget); unit.FireSkillProjectile(nearbyOpponent != null ? nearbyOpponent : mainTarget); } private GameObject FindNearbyOpponent(GameObject mainTarget) { UnitTeam myTeam = unit.GetComponent(); if (myTeam == null) { return null; } GameObject nearbyOpponent = null; float nearestSqrDistance = splitShotRadius * splitShotRadius; foreach (UnitTeam opponentTeam in GameObject.FindObjectsOfType()) { GameObject opponent = opponentTeam.gameObject; if (opponent == null || opponent == mainTarget || opponent == unit.gameObject || opponent.transform.root == unit.transform.root || !myTeam.IsEnemy(opponent)) { continue; } float sqrDistance = (opponent.transform.position - mainTarget.transform.position).sqrMagnitude; if (sqrDistance <= nearestSqrDistance) { nearestSqrDistance = sqrDistance; nearbyOpponent = opponent; } } return nearbyOpponent; } }