receiveDamage method

void receiveDamage(
  1. AttackFromEnum attacker,
  2. double damage,
  3. dynamic identify
)

This method is called to give damage a this component. Only receive damage if the method checkCanReceiveDamage return true.

Implementation

void receiveDamage(
  AttackFromEnum attacker,
  double damage,
  dynamic identify,
) {
  if (checkCanReceiveDamage(attacker, damage, identify)) {
    if (life > 0) {
      life -= damage;
    }
    if (life <= 0 && !_isDead) {
      die();
    }
  }
}