twinStick/twinStickCrawler/Assets/Scripts/Creatures/Animate.cs
2024-12-23 18:13:28 +01:00

48 lines
1.2 KiB
C#

using System;
using UnityEngine;
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 OnReset;
void LeftReset(AnimationEvent animationEvent)
{
OnReset?.Invoke();
}
void RightReset(AnimationEvent animationEvent)
{
OnReset?.Invoke();
}
void KickReset(AnimationEvent animationEvent)
{
OnReset?.Invoke();
}
}