WXMC/.svn/pristine/b3/b31d65c5e4f88d89d4a445616f8c468e00ba8f24.svn-base
2024-12-04 16:18:46 +08:00

44 lines
960 B
Plaintext

using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PHomeHumanUnitAnimation : MonoBehaviour
{
[SerializeField]
private PHomeUnit m_unit;
[SerializeField]
private SkeletonAnimation m_skeletonAnimation;
[SpineAnimation]
public string MoveAnim;
[SpineAnimation]
public string IdleAnim;
// private void Update_Anim()
// {
// #if UNITY_EDITOR
// Vector2 velocity = Vector2.right * Input.GetAxisRaw("Horizontal") + Vector2.up * Input.GetAxisRaw("Vertical");
// Anim(velocity);
// #endif
// }
public void Anim()
{
Vector2 finaleVel = m_unit.PhysicsBody.velocity;
bool moving = finaleVel.sqrMagnitude > 0.001f;
string animName = moving ? MoveAnim : IdleAnim;
m_skeletonAnimation.AnimationName = animName;
}
private void LateUpdate()
{
Anim();
}
}