//update the attack entity when there's a target protected virtual void OnTargetUpdate() { //the override of this method in both the UnitAttack and BuildingAttack components are responsible for checking the conditions for which an attack can be continued or not //reaching this stage means that all conditions have been met and it's safe to continue with the attack if (wasInTargetRange == false) //if the attacker never was in the target's range but just entered it: { attackerInRangeEvent.Invoke(); CustomEvents.OnAttackerInRange(this, Target, GetTargetPosition()); //launch custom event wasInTargetRange = true; //mark as in target's range. initialEngagementDistance = Vector3.Distance(transform.position, GetTargetPosition()); } weapon.UpdateActiveRotation(GetTargetPosition()); if (reloadTimer > 0 || IsInLineOfSight() == false) //still in reload time or not facing target? do not proceed { return; } if (delayTimer > 0) //delay timer { delayTimer -= Time.deltaTime; return; } //If the attack delay is over, the attack is triggered and LOS conditions are met if (triggered) { if (direct == true) //Is this a direct attack (no use of attack objects)? { attackPerformedEvent.Invoke(); //not an area attack: CustomEvents.OnAttackPerformed(this, Target, GetTargetPosition()); damage.TriggerAttack(Target, GetTargetPosition()); AudioManager.Play(FactionEntity.AudioSourceComp, attackAudio, false); OnAttackComplete(); } else if (attackObjectLauncher.OnIndirectAttackUpdate()) //indirect attack ? -> must launch attack objects { AudioManager.Play(FactionEntity.AudioSourceComp, attackAudio, false); } } }