Player Attack

The PlayerAttack class is responsible for player's attack actions, including target detection within a certain range, managing attack states, and coordinating with the animation system to reflect the player's actions visually.

Properties

  • private PlayerWorker playerWorker: References the PlayerWorker associated with PlayerAttack

  • private SingleRangeChecker singlePlayerRangeChecker: References the module for detecting other players within a specified range of the player.

  • private SingleRangeChecker singleEnemyRangeChecker: References the module for detecting enemies within a specified range of the player.

  • public Element target: References the current target of the player's attack.

  • private bool isAttacking: Represents whether the player is currently in the process of attacking.

Constructor

  • public PlayerAttack(PlayerWorker playerWorker): Initializes a new instance of the PlayerAttack class while assigning the PlayerWorker and setting up range checkers for detecting targets.

Methods

  • public void Attack(): Initiates the attack process and checks if the player is already attacking or if there are valid targets. If a target is present, it sets the player to the attacking state, plays the attack animation, determines the target, and applies damage to it. Finally, it starts a coroutine to reset the attack state after a delay.

  • public IEnumerator ResetState(): A coroutine that resets the player's attack state and animation after a specified delay, allowing for a cooldown period between attacks.

Last updated