Eye of the Nile Docs
Everything you need to know to get started!
Loading...
Searching...
No Matches
PlayerAttackManager Class Reference

Detailed Description

Handles all the attacks the player can perform, including both standard attacks and all ability attacks. This script contains multiple overloads of some functions to provide more functionality if desired.

Documentation updated 8/30/2024

Author
Stephen Nuttall
Note
If you're writing an ability info and you want to access one of these functions, you can reach them with "abilityOwner.OwnerTransform.GetComponent<PlayerAttackManager>().[function name goes here]"

Public Member Functions

void Melee (string animName, float cooldown)
 Sets up the variables for TriggerMelee(), and then triggers the attack animation and cooldown.
 
void Melee (string animName, float cooldown, float range, float kbStrength)
 Sets up the variables for TriggerMelee(), and then triggers the attack animation and cooldown. This overload provides two extra parameters to customize the range and knockback.
 
void ShootProjectile (GameObject projectilePrefab)
 Spawn a projectile from the attack point and set it facing the correct direction. No cooldown overload. This will not start a cooldown and will ignore the current cooldown.
 
void ShootProjectile (GameObject projectilePrefab, float cooldown)
 Spawn a projectile from the attack point and set it facing the correct direction. Then start the attack cooldown.
 
void ShootProjectileBurst (GameObject projectilePrefab, int numProjectiles, float delay)
 Will start a coroutine for ProjectileBurst, which F\fires a projectile numProjectiles times, wtih delay seconds in between.
 

Private Member Functions

void Awake ()
 Set reference to the PlayerStatsHolder.
 
void Update ()
 Every frame, check if the user is pressing the melee key or projectile key.
 
void MeleeTrigger ()
 This function is triggered by the melee animation at the peak of the sword swing. At that moment, the actual melee attack happens.
 
IEnumerator CooldownWait (float seconds)
 Prevents any attacks that observe the attack cooldown from triggering for the given amount of seconds.
 
IEnumerator ProjectileBurst (GameObject projectilePrefab, int numProjectiles, float delay)
 Fires a projectile numProjectiles times, wtih delay seconds in between.
 

Private Attributes

PlayerStatHolder playerStats
 Reference to the PlayerStatsHolder, which is responsible for managing the player's modifiable stats.
 
Transform attackPoint
 Reference to the player's's attack point. It's a point in space that's a child of the player, existing some distance in front of it. Projectiles spawn from the attack point, and melee attacks scan for enemies to damage from a certain radius around it.
 
LayerMask attackableLayers
 Objects on these layers which can be hit from the player's melee attacks.
 
Animator animator
 Reference the the player's animator.
 
bool onCooldown = false
 True if attacking is on cooldown, preventing another attack from being used.
 

Default Melee Attack

Information related to the player's default melee attack.

KeyCode meleeKey = KeyCode.Mouse0
 
string meleeAnimation = "Attack"
 Name of the animation to play.
 
float curRange
 The melee range that will be used for the next attack. If no range parameter is given to Melee(), this will be set to meleeRange by default.
 
float curKnockback
 The melee knockback that will be used for the next attack. If no range parameter is given to Melee(), this will be set to meleeKnockback by default.
 

Default Projectile Attack

Information related to the player's default projectile attack.

KeyCode projectileKey = KeyCode.Mouse1
 
GameObject defaultProjectilePrefab
 Reference to the projectile this attack will instantiate.
 
float ProjCooldown = 1f
 Cooldown time for all attacks must wait after the projectile attack is used.
 

Member Function Documentation

◆ Awake()

void PlayerAttackManager.Awake ( )
private

Set reference to the PlayerStatsHolder.

◆ CooldownWait()

IEnumerator PlayerAttackManager.CooldownWait ( float seconds)
private

Prevents any attacks that observe the attack cooldown from triggering for the given amount of seconds.

Parameters
secondsHow long the cooldown should last, in seconds.

◆ Melee() [1/2]

void PlayerAttackManager.Melee ( string animName,
float cooldown )

Sets up the variables for TriggerMelee(), and then triggers the attack animation and cooldown.

Parameters
animNameName of the attack animation.
cooldownLength of the attack cooldown after this ability is triggered.

◆ Melee() [2/2]

void PlayerAttackManager.Melee ( string animName,
float cooldown,
float range,
float kbStrength )

Sets up the variables for TriggerMelee(), and then triggers the attack animation and cooldown. This overload provides two extra parameters to customize the range and knockback.

Parameters
animNameName of the attack animation.
cooldownLength of the attack cooldown after this ability is triggered.
rangeThe distance from the attack point that enemies will be hit by the melee attack (size of attack point).
kbStrengthThe strength of the knockback the melee attack will apply.

◆ MeleeTrigger()

void PlayerAttackManager.MeleeTrigger ( )
private

This function is triggered by the melee animation at the peak of the sword swing. At that moment, the actual melee attack happens.

Scan for enemies in curRange radius of the attack point.

For each one found:

  • Deal the amount of damage dictated by the PlayerStatsHolder (if it has an ObjectHealth component),
  • Apply knockback with curKnockback strength (if it has a KnockbackFeedback component),

◆ ProjectileBurst()

IEnumerator PlayerAttackManager.ProjectileBurst ( GameObject projectilePrefab,
int numProjectiles,
float delay )
private

Fires a projectile numProjectiles times, wtih delay seconds in between.

Parameters
projectilePrefabReference the projectile the attack will instantiate.
numProjectilesNumber of projectiles to spawn.
delayHow much time between each projectile spawning, in seconds.

◆ ShootProjectile() [1/2]

void PlayerAttackManager.ShootProjectile ( GameObject projectilePrefab)

Spawn a projectile from the attack point and set it facing the correct direction. No cooldown overload. This will not start a cooldown and will ignore the current cooldown.

Parameters
projectilePrefabReference the projectile the attack will instantiate.

◆ ShootProjectile() [2/2]

void PlayerAttackManager.ShootProjectile ( GameObject projectilePrefab,
float cooldown )

Spawn a projectile from the attack point and set it facing the correct direction. Then start the attack cooldown.

Parameters
projectilePrefabReference the projectile the attack will instantiate.
cooldownLength of the attack cooldown after this ability is triggered.

◆ ShootProjectileBurst()

void PlayerAttackManager.ShootProjectileBurst ( GameObject projectilePrefab,
int numProjectiles,
float delay )

Will start a coroutine for ProjectileBurst, which F\fires a projectile numProjectiles times, wtih delay seconds in between.

Parameters
projectilePrefabReference the projectile the attack will instantiate.
numProjectilesNumber of projectiles to spawn.
delayHow much time between each projectile spawning, in seconds.

◆ Update()

void PlayerAttackManager.Update ( )
private

Every frame, check if the user is pressing the melee key or projectile key.

Member Data Documentation

◆ animator

Animator PlayerAttackManager.animator
private

Reference the the player's animator.

◆ attackableLayers

LayerMask PlayerAttackManager.attackableLayers
private

Objects on these layers which can be hit from the player's melee attacks.

◆ attackPoint

Transform PlayerAttackManager.attackPoint
private

Reference to the player's's attack point. It's a point in space that's a child of the player, existing some distance in front of it. Projectiles spawn from the attack point, and melee attacks scan for enemies to damage from a certain radius around it.

◆ curKnockback

float PlayerAttackManager.curKnockback
private

The melee knockback that will be used for the next attack. If no range parameter is given to Melee(), this will be set to meleeKnockback by default.

Note
The reason there need to be a separate variable is because TriggerMelee() is run by the animation at the peak of the sword swing, rather than being directly called. Therefore, it cannot have parameters passed to it like a normal function call.

◆ curRange

float PlayerAttackManager.curRange
private

The melee range that will be used for the next attack. If no range parameter is given to Melee(), this will be set to meleeRange by default.

Note
The reason there need to be a separate variable is because TriggerMelee() is run by the animation at the peak of the sword swing, rather than being directly called. Therefore, it cannot have parameters passed to it like a normal function call.

◆ defaultProjectilePrefab

GameObject PlayerAttackManager.defaultProjectilePrefab
private

Reference to the projectile this attack will instantiate.

◆ meleeAnimation

string PlayerAttackManager.meleeAnimation = "Attack"
private

Name of the animation to play.

◆ meleeKey

KeyCode PlayerAttackManager.meleeKey = KeyCode.Mouse0
private

Key the user must press to activate this attack.

◆ onCooldown

bool PlayerAttackManager.onCooldown = false
private

True if attacking is on cooldown, preventing another attack from being used.

◆ playerStats

PlayerStatHolder PlayerAttackManager.playerStats
private

Reference to the PlayerStatsHolder, which is responsible for managing the player's modifiable stats.

◆ ProjCooldown

float PlayerAttackManager.ProjCooldown = 1f
private

Cooldown time for all attacks must wait after the projectile attack is used.

◆ projectileKey

KeyCode PlayerAttackManager.projectileKey = KeyCode.Mouse1
private

Key the user must press to activate this attack.


The documentation for this class was generated from the following file: