Merlins Beard . Attack System . Attack

The Attack component exists on a different game object than the Attacker, though it could be a child of the Attacker. The Attack Target component references an Attack component and uses it to determine range, whether or not to face the target and what kind of special visual and sound effects need to be played.

Serialized Fields

The Attacker field needs to be set prior to playing the game. The field is looking for a Mover object as this is used to ensure the character is rotated to face the thing it is trying to hit. In the future, this will be set automatically. It is used to trigger the attacking animations and for calculating ranges.

The Range is a temporary field that determines how far away an Attacker can be before triggering an Attack. Future iterations may pull this value from the Weapon.

The Arc is a degree field that the Attacker uses to determine when an attack can be triggered, the idea being you should only swing at things that are in front of you.

The Layer Mask restricts Raycasts looking for valid Targets to specific layers of the game world.

Attack Started :: Unity Event

The Attack Started event starts the Cooldown for the Attack and triggers the Attack Animator. It can also be used to start special FX.

Attack Ended :: Unity Event

The Attack Ended event is used to end special effects.

Deal Damage :: Unity Event <Health>

Deal Damage is triggered for every game object that has a Health component in the Attack’s area of effect. The event passes the Health component of each valid target to its listeners.

Public Properties

Range :: float
Arc :: float


Execute ( Target )

Sets the Attacker’s Attacking flag and then invokes the Attack Started event.

On Hit ( )

This method looks for Targets with Health components using a Boxcast and then invokes the Deal Damage event on each of those Targets.