Unity学习笔记-2D Animation

脚本控制的动画播放有两种方式

a. 通过动画名直接播放

animator.Play("Animation name");

** animator.Play还可以设置动画的播放起点 - 可用来让动画从随机一帧开始播放 **
** animator.Play(" animation_name", int layer, float start_point); **
** layer默认是-1,start_point设为Random.Range(0f, 1f)即可实现随机起点播放 **

b. 通过将播放参数设为true来播放

animator.SetTrigger("参数名"); 置为true
animator.ResetTrigger("参数名"); 置为false

判断动画是否播放结束

if(this.animator.GetCurrentAnimatorStateInfo(0).IsName("YourAnimationName"))

 {

     // Avoid any reload.

     this.InMyState = true;

 }

 else if (this.InMyState)

 {

     this.InMyState = false;

     // You have just leaved your state!

 }

你可能感兴趣的:(Unity学习笔记-2D Animation)