/// <summary> /// Take Agent's health, locking his components for specified /// amount of time and inducingspecific sound and animation. /// </summary> /// <param name="value"></param> public void Damage(int value) { if (!_useHealth) { return; } _agent.GetAudioSource().PlayRandomClip(_onDamageSounds); _curHealthPoints = Mathf.Max(0, _curHealthPoints - value); if (_curHealthPoints < 0) { _curHealthPoints = 0; } if (_lockTime > 0) { _agent.Motion.Lock(); } if (_alive && _curHealthPoints <= 0) { _alive = false; Death.Die(); } // Check wheather Agent needs to animate the damage. var animate = true; try { animate = !((_agent.CurrentSkill.State == SkillState.Loading || _agent.CurrentSkill.State == SkillState.Invoking) && !_agent.CurrentSkill.Interruptible); } catch (Exception) { /*ignore*/ } if (animate) { switch (_agentAnimation.AnimationMode) { case AnimationMode.Legacy: _agentAnimation.Animate(AnimationState.TakingDamage, 0, true); break; case AnimationMode.Mecanim: _agentAnimation.Animate(_agentAnimation.Parameters.TakeDamageTrigger, _lockTime); break; } } if (_lockTime > 0) { _agent.StartCoroutine(UnlockMovementEnum()); } }
/// <summary> /// Quick move in certain direction, with a corresponding animation. /// </summary> /// <param name="direction"></param> public void Dodge(string direction) { if (_locked) { return; } if (!_canDodge) { return; } _canDodge = false; _agent.StartCoroutine(DodgeEnum(direction)); _motion.PlayAudio(_motion.DodgingSounds, 0); }
/// <summary> /// Trigger the execution of the skill. /// </summary> public void Invoke() { if (_skillAvailable && TrySpendEnergy(_energyCost)) { _agent.StartCoroutine(INTERNAL_LoadEnum()); _agent.CurrentSkill = this; } }
/// <summary> /// Trigger Animator by message. /// </summary> /// <param name="triggerMessage">Sets the value of the given Animator parameter.</param> /// <param name="duration"></param> public void Animate(string triggerMessage, float duration = 0.1f) { _animator.SetTrigger(triggerMessage); _agent.StartCoroutine(ResetTriggerEnum(triggerMessage, duration)); }