44 lines
960 B
Plaintext
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();
|
||
|
}
|
||
|
}
|