void Update() { // Can only attack when the timer is greater than attack speed, hence; // Greater attack speed value actually means more time between attacks attackTimer += 0.5f * Time.deltaTime; // If there is no target to attack, then find a target in range if (target == null) { SetTarget(tc.AcquireTarget()); // Else if there is a target, attack if in range or move to it if not in range } else { if (ProgUtils.InRange(gameObject, target, attackRange)) { if (ProgUtils.InLineOfSight(gameObject, target)) { tc.Stop(); Attack(); } else if (tc.IsStopped()) { tc.Move(target.transform.position); } } else { tc.Move(ProgUtils.GetNearestWithinRange(gameObject, target, attackRange - 2f)); } } }
//Delegated helper function for MoveTroops static void MoveTroop(TroopClass troop) { if (target == null) { troop.ClearCombatTarget(); } troop.Move(pointSelected); }
//Delegated helper function for MoveTroops void MoveTroop(TroopClass troop) { troop.Move(pointSelected, true); }