/// <summary> /// APPLY DAMAGE - call this method by a SendMessage with the damage value /// </summary> /// <param name="damage"> damage to apply </param> public override void TakeDamage(Damage damage) { // become agressive and starts to chase the target SetAgressive(true); // ignore damage if the character is rolling if (rolling || currentHealth <= 0) { return; } if (canSeeTarget() && !damage.ignoreDefense && !actions && CheckChanceToRoll()) { return; } // change to block an attack StartCoroutine(CheckChanceToBlock(chanceToBlockAttack, 0)); // defend attack behaviour if (canSeeTarget() && BlockAttack(damage)) { return; } // instantiate hit particle var hitRotation = Quaternion.LookRotation(new Vector3(transform.position.x, damage.hitPosition.y, transform.position.z) - damage.hitPosition); SendMessage("TriggerHitParticle", new HittEffectInfo(new Vector3(transform.position.x, damage.hitPosition.y, transform.position.z), hitRotation, damage.attackName), SendMessageOptions.DontRequireReceiver); // apply damage to the health currentHealth -= damage.value; currentHealthRecoveryDelay = healthRecoveryDelay; // apply tag from the character that hit you and start chase if (!sphereSensor.passiveToDamage && damage.sender != null) { target = damage.sender; currentState = AIStates.Chase; sphereSensor.SetTagToDetect(damage.sender); if (meleeManager != null) { meleeManager.SetTagToDetect(damage.sender); } } // trigger hit sound if (damage.sender != null) { damage.sender.SendMessage("PlayHitSound", SendMessageOptions.DontRequireReceiver); } // update the HUD display if (healthSlider != null) { healthSlider.Damage(damage.value); } // trigger the HitReaction when the AI take the damage var hitReactionConditions = stepUp || climbUp || jumpOver || quickTurn || rolling; if (animator != null && animator.enabled && !damage.activeRagdoll && !hitReactionConditions) { animator.SetInteger("Recoil_ID", damage.recoil_id); animator.SetTrigger("HitReaction"); } // turn the ragdoll on if the weapon is checked with 'activeRagdoll' if (damage.activeRagdoll) { transform.SendMessage("ActivateRagdoll", SendMessageOptions.DontRequireReceiver); } CheckHealth(); }