【瑞模网】Unity动画触发方法总结

Unity动画触发方法总结

需求

UI动画希望玩家点击一次就播放一次

一、SetActive

这种情况需要在动画播放完毕后,将animator所在 gameobject设置为 inactive;或者在每次点击时先将gameObject设置为inactive,再timer(0.01s)设置为active;

二、Animator类方法

Animator.settrigger: 这种方法需要在animator里自己添加状态转移参数

Animator.Play(“StateName”); 这个函数要注意它的参数默认值,单独这样写是永远不会执行的。要写成Animator.Play(“StateName”,0,0);

考虑使用hashid的函数重载;Animator.Play(hashid); 但是hashid也需要通过StateName来得到:int stateHash = Animator.StringToHash( stateName );

这种方法,依赖于stateName;一旦stateName改变了,这种方法也就时效了

三、回调

这种方法希望在动画播放完之后通过回调函数,将gameobject设置为false;

  1. Animator Controller中的状态上,都可以挂继承自类StateMachineBehavior的脚本

  1. StateMachineBehavious的OnStateExit方法

  1. NGUI自带的UIPlayAnimation 脚本

猜你喜欢

转载自blog.csdn.net/rrmod/article/details/128975205