/// <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> /// Start loading the skill. /// </summary> /// <returns></returns> private IEnumerator INTERNAL_LoadEnum() { _agent.GetAudioSource().PlayRandomClip(_loadingSkillSounds); _state = SkillState.Loading; if (_freezeMotion) { _agent.Motion.Lock(); } AnimateLoading(); _skillAvailable = false; yield return(new WaitForSeconds(_loadTime + UnityEngine.Random.Range(-LoadTimeError, LoadTimeError))); if (!_interrupted) { _agent.StartCoroutine(INTERNAL_InvokeEnum()); } else { _interrupted = false; _agent.StartCoroutine(INTERNAL_CoolDownEnum()); } }