using System; using UnityEngine; namespace Creatures { public class Animate : MonoBehaviour { private Animator _animator; private RuntimeAnimatorController _animatorController; public void initialize(Animator animator) { _animator = animator; _animatorController = animator.runtimeAnimatorController; } public void AnimateState(string animVar, float animVal, float animationSpeed) { float t = Mathf.Clamp01(animationSpeed*Time.deltaTime); float newVal = Mathf.Lerp(_animator.GetFloat(animVar), animVal, t); _animator.SetFloat(animVar, newVal); //animator.Play("Attack"); //print(animator.GetCurrentAnimatorStateInfo(1).IsName("Idle")); } public bool IsCurrentAnimation(string name) { return _animator.GetCurrentAnimatorStateInfo(0).IsName(name); } public void TriggerAnimation(string triggerName) { _animator.SetTrigger(triggerName); } public event Action OnStartDamage; public event Action OnEndDamage; public event Action OnReset; public event Action OnAnimationEnd; void LeftReset(AnimationEvent animationEvent) { OnReset?.Invoke(); } void RightReset(AnimationEvent animationEvent) { OnReset?.Invoke(); } void KickReset(AnimationEvent animationEvent) { OnReset?.Invoke(); } void StartDamage(AnimationEvent animationEvent) { OnStartDamage?.Invoke(); } void EndDamage(AnimationEvent animationEvent) { OnEndDamage?.Invoke(); } void AnimationEnd(AnimationEvent animationEvent) { OnAnimationEnd?.Invoke(); } } }