Unity 动画系统

Legacy动画系统:Animation组件(旧)

Mecanim动画系统:Animator组件(新)

动画播放过程:

//动画片段
[System.Serializable]
public class Anim
{
public AnimationClip idle;
public AnimationClip runForward;
public AnimationClip runBackward;
public AnimationClip runRight;
public AnimationClip runLeft;
} public class PlayerCtrl : MonoBehaviour
{
public Anim anim;
public Animation _animation; void Start()
{
tr = GetComponent<Transform>();
_animation = GetComponentInChildren<Animation>(); //_animation.clip = anim.idle;
//_animation.Play();
} void Update()
{
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical"); Vector3 moveDir = (Vector3.forward * v) + (Vector3.right * h);
tr.Translate(moveDir.normalized * Time.deltaTime * moveSpeed, Space.Self);
tr.Rotate(Vector3.up * Time.deltaTime * rotSpeed * Input.GetAxis("Mouse X")); if (v >= 0.1F)
{
_animation.CrossFade(anim.runForward.name, 0.3F);
}
else if (v <= -0.1F)
{
_animation.CrossFade(anim.runBackward.name, 0.3F);
}
else if (h >= 0.1F)
{
_animation.CrossFade(anim.runRight.name, 0.3F);
}
else if (h <= -0.1F)
{
_animation.CrossFade(anim.runLeft.name, 0.3F);
}
else
{
_animation.CrossFade(anim.idle.name, 0.3F);
}
}

这个过程是很重要的,通过获取到的坐标的大小进行播放不同的动画,并且有着平稳的过度。

上一篇:【五】PHP数组操作函数


下一篇:NSTImer重复执行任务