twinStick/twinStickCrawler/Assets/Scripts/Creatures/Animate.cs

67 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System;
2024-12-19 11:36:55 +00:00
using UnityEngine;
2024-12-24 20:40:18 +00:00
namespace Creatures
2024-12-19 11:36:55 +00:00
{
2024-12-24 20:40:18 +00:00
public class Animate : MonoBehaviour
2024-12-20 14:21:20 +00:00
{
2024-12-24 20:40:18 +00:00
private Animator _animator;
private RuntimeAnimatorController _animatorController;
public void initialize(Animator animator)
{
_animator = animator;
_animatorController = animator.runtimeAnimatorController;
}
2024-12-23 17:13:28 +00:00
2024-12-24 20:40:18 +00:00
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);
2024-12-24 20:40:18 +00:00
//animator.Play("Attack");
//print(animator.GetCurrentAnimatorStateInfo(1).IsName("Idle"));
}
2024-12-20 14:21:20 +00:00
2024-12-24 20:40:18 +00:00
public bool IsCurrentAnimation(string name)
{
return _animator.GetCurrentAnimatorStateInfo(0).IsName(name);
}
2024-12-23 17:13:28 +00:00
2024-12-24 20:40:18 +00:00
public void TriggerAnimation(string triggerName)
{
_animator.SetTrigger(triggerName);
}
2024-12-23 20:34:57 +00:00
2024-12-24 20:40:18 +00:00
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();
}
2024-12-23 20:34:57 +00:00
2024-12-24 20:40:18 +00:00
void AnimationEnd(AnimationEvent animationEvent)
{
OnAnimationEnd?.Invoke();
}
2024-12-23 20:34:57 +00:00
}
2024-12-19 11:36:55 +00:00
}