Add the Attack component to the unit/building main object in order to allow it to attack enemy units/buildings.
General Attack Settings:
- Attacker: The attacker type, either a unit or a building.
- Attack Code: Unique code for this attack.
- Attack Icon: Icon that represents the attack (this is only used when the attacker is a unit and it has more than one attack type, the icon will be used in the task panel allowing the player to switch attack types).
- Basic Attack: When there are more than one attack type per unit then one of them should be selected as the basic attack type, the basic attack type is the one that is activated for the unit per default.
- Attack Reload: Time (in seconds) between two consecutive attacks.
- Attack All Types: When enabled, then the attacker will be able to attack all unit/building types without exceptions. When disabled, the following settings will appear:
- Attack Units: Disable if you don’t want the attacker to attack units.
- Attack Buildings: Disable if you don’t want the attacker to attack buildings.
- Attack Exceptions (Codes): Unit/building codes that represents units and buildings that the attacker can’t attack.
- Range Type Code (units): Input the code of the range type that the unit belongs to (Range Types are explained in the Attack Manager documentation page).
Attack Unit Settings:
The following settings will only appear if the attacker type is set to “Unit”.
- Attack On Assign: Enable if you’d like the player to pick and assign targets (with the right-mouse button) for the unit to attack.
- Attack When Attacked: Enable if you’d like the unit to attack back when a unit/building attacks it (if it doesn’t has an attack target already).
- Attack Once: Enable if you’d like the unit to only attack once and then the attack target has to be assigned again.
- Move On Attack: Enable if you’d like the unit to launch attacks while moving.
- Attack In Range: Enable if you’d like the unit to search for targets inside a defined range and attack them. When enabled, two options will be displayed.
- Search Range: This is the range where the unit is allowed to search for targets.
- Search Reload: Time between each search for targets to attack.
- Follow Distance: If the target decides to run away, this value represents how far the unit will follow the target. If the target’s distance exceeds the value in this field, then the attack will be cancelled.
- Play Animation In Delay: Enable if you’d like to play the attack animation as soon as the delay timer starts (not the actual attack). Delay is further explained below.
- Attack Animation Duration: Input the duration of the unit’s attack animation in this field.
Attack Damage Settings:
- Deal Damage: Enabled if you’d like the attacker to deal damage to its target (when this is disabled, attack-related custom delegate events will still be called so you can choose what happens instead of dealing damage).
- Area Damage: Enabled if you’d like the attacker to cause damage that covers a whole area and not a single unit/building. When this option is enabled, the following options will appear: The Attack Ranges array allows you to define areas where different damage points will be dealt to units/building depending on their distance from the original attack position. Each element of the array represents an area, areas must be defined from the closest areas to the attack source to the furthest.
- Range: Size of the area where the damage will be applied.
- Unit Damage: The damage that will be dealt to units in this area.
- Building Damage: The damage that will be dealt to buildings in this area.
- Unit/Building Damage: If the Area Damage option is disabled, the two fields “Building Damage” and “Unit Damage” will appear where you can define how many damage points this attack deals to units/buildings.
- Damage Over Time (DoT): It’s also possible to apply damage over time. The damage points defined in the above two fields (whether it’s area damage or not) will be applied over time. When this option is enabled, the following fields will appear:
- Infinite DoT: If enabled, the DoT will be applied to the attack target till the target is dead/destroyed or you the DoT is stopped with your custom code.
- DoT Duration: If the DoT is not infinite, then you need to input how much it will lasts in this field (in seconds).
- DoT Cycle: The time period (in seconds) at which the damage will be applied to DoT victim (if DoT Cycle is set to 4, then every 4 seconds the damage will be applied).
- Reload Dealt Damage: All damage points applied from the attacker are accumulated and saved in the float type attribute “DamageDealt” of the Attack class. This allows you to reward the attacker when he deals X amount of damage. This value can be reloaded each time if this option is enabled (each time the target acquires a new attack target, the value of “DamageDealt” will reset).
- Attack Delay Time: Before the attack is launched, a delay time can be assigned that delays the attack (this especially useful when you want to start the attack animation for a unit before the actual attack is launched so the trick here is to set the attack delay time to the value at which the unit attack animations progresses enough to launch the attack, then enabled the “Play Animation In Delay” option.
- Use Delay Trigger: When enabled, then in addition to the attack delay time, it is required that you access the “AttackTriggered” bool attribute in the unit’s Attack component and set it to true in order to trigger the attack. This allows for more customization for the Attack component.
- Use Cooldown: When enabled, the unit won’t be able to launch an attack when in cooldown mode.
- Cooldown duration: Duration of the cooldown if it’s enabled.
Direct Attack/Attack Object:
- Direct Attack: When enabled then the damage will be directly applied to the attack target when the attack is launched. When disabled, the attacker will create an Attack Object and launch it towards the target, the damage is then applied only if the Attack Object hits the target.
- Indirect Attack/Attack Objects: When Direct Attack is disabled, then the Attack Sources array will appear in the inspector and right above it is the Attack Type field: When using attack objects, there can be two types of attacks: either Random or In Order. Since it is allowed to have multiple attack sources (multiple attack objects as well), only one attack source will be chosen and the attack object will be released from there if the attack type is random. If the attack type is in order then all the attack sources will launch the attack objects in the same order that they are added in the Attack Sources array. The In Order mode allows the attacker to have a more complex attack where for example a robot with multiple machine guns attached to it can attack with bullets coming out from all machine guns at the same time or with a delay between each shot. Attack sources, objects are managed in the Attack Sources array:
- Attack Delay: Time (in seconds) before the attack is launched from this source.
- Attack Obj: The attack object prefab. This object must have both the EffectObj and AttackObject as components. For the EffectObj component, please check this documentation page for an explanation of its fields in the inspector. As for the AttackObject component, it only has one field: Spawn Effect. The SpawnEffect is also an effect object spawned as soon as the attack object is created, it can be a muzzle flash for a bullet for example. Please check this documentation page for more information about effect objects. The attack object also includes a collider that has “Is Trigger” set to false and a rigidbody component with fixed rotation and position on all axis, in addition to having “Is Kinematic” set to false and “Use Gravity” set to false.
- Attack Obj Destroy Time: Life duration of the attack object before it gets destroyed.
- Attack Obj Source: Where should the attack object spawn at? It should be either the main unit/building transform or a transform that belongs to a child object of the unit/building prefab.
- Attack Obj Speed: Speed of the attack object when it moves towards the target.
- Damage Once: When enabled then the attack object will only do damage to the first enemy unit/building it hits.
- Destroy On Damage: When enabled, the attack object will be destroyed as soon as it hits an enemy unit/building.
- Attack Effect: This object is spawned at the target’s position whenever damage has been dealt either with a direct attack or using an attack object. Please check this documentation page for more information about effect objects and the EffectObj component.
- Attack Effect Duration: If an Attack Effect is assigned, then this field represents the life duration of this effect object before it gets hidden.
- Weapon Object (optional): It is possible to have a weapon object that acts as the parent object of the attack source. Assigning that weapon object to this field will allow the unit/building to rotate it to face the attack target making the whole attack process more realistic. All the following fields in this part should be only considered when this field is not empty.
- Freeze Rotation on X, Y and/or Z: When rotating the weapon object, you can pick to block rotation on one or a combination of the three axis.
- Smooth Rotation: When enabled then the rotation of the weapon object to face the attack target will be done smoothly. When disabled, the weapon object will directly rotate to face the target.
- Rotation Damping: Determines how smooth the weapon object rotation is, if the above option is enabled.
- Weapon Idle Angles: When the attacker is in idle mode (does not have a target), then the weapon object will take this rotation (the rotation is defined here by Euler Angles).
Attack Audio Settings:
- Attack Order Sound: An audio clip played when the player gives an order for this attacker to launch an attack.
- Attack Sound: An audio clip played every time the attacker launches an attack.