public List <Transform> FindAllTargetsWithinRadius(Transform seeker, int thisPlayer, float searchRadius) { List <Transform> unitsWithinRadius = new List <Transform>(); HashSet <Transform> playerUnits = (thisPlayer == 1) ? player2Units : player1Units; TargetClass targets = seeker.GetComponent <UnitTargetInfo>().targets; foreach (Transform unit in playerUnits) { TargetClass characteristcs = unit.GetComponent <UnitTargetInfo>().characteristcs; if ((targets & characteristcs) != 0) //Checks that the Seeker can actually target the unit { IBehaviourStats behaviourScript = unit.GetComponent <IBehaviourStats>(); float sizeRadius = behaviourScript.GetSizeRadius(); if (Vector2.Distance(seeker.position, unit.position) <= searchRadius + sizeRadius) //Checks that the unit is within a searchRadius centering from Seekers transform, eg. Fireball effect { unitsWithinRadius.Add(unit); } } } return(unitsWithinRadius); }
private void Start() { animator = GetComponentsInChildren <Animator>(); aiScript = transform.parent.GetChild(transform.GetSiblingIndex() - 1).GetComponent <IBehaviourStats>(); agent = transform.parent.GetChild(transform.GetSiblingIndex() - 1).GetComponent <NavMeshAgent>(); }