永发信息网

animator下怎么控制指定动画的播放速度

答案:2  悬赏:10  手机版
解决时间 2021-03-03 02:23
  • 提问者网友:留有余香
  • 2021-03-02 13:36
animator下怎么控制指定动画的播放速度
最佳答案
  • 五星知识达人网友:玩世
  • 2021-03-02 14:04
animation.speed = 0.5F;
animation.Play("walk");
yield return new WaitForSeconds(animation["walk"]);//等待播放完毕
animation.speed = 1; //调整回原来的速度
animation.Play("Idle");//播放回原来的动画

或者你调整Time.timeScale,缩放时间值,这样也可以达到控制动画速度的目的,但是副作用是其他模型的动画速度也会变成慢动作。大概流程跟上方的一致。

PS:我实验了一下,事实上楼主你这样的方式也是可以的: m_animation["ANI_SWIM"].speed = 0.1f; //ANI_SWIM是模型的动画序列名称
我在Start()里面设置如上,然后SWIM动画会放慢10倍,但是其他动画播放不受影响,可以实现楼主需要的功能。
全部回答
  • 1楼网友:像个废品
  • 2021-03-02 15:27
1,如果要改变速度的动画不多,比如就要停止和正常播放两种状态,可以使用blend tree 进行分支处理,一个是速度为0,一个为1的。 2,使用time.timescale.这没有深入研究,发现很多网站都有提及到。 3,使用unityeditorinternal unityeditorinternal.animatorcontroller ac = animator.runtimeanimatorcontroller as unityeditorinternal.animatorcontroller; unityeditorinternal.statemachine sm = ac.getlayer(1).statemachine; for (int i = 0; i < sm.statecount; i++) { unityeditorinternal.state state = sm.getstate(i); state.speed = 2; debug.log(state.uniquename + " " + state.speed); } void setanimspeedwithcliptag(int layer, string tag, float speed) { unityeditorinternal.animatorcontroller ac = animator.runtimeanimatorcontroller as unityeditorinternal.animatorcontroller; unityeditorinternal.statemachine sm = ac.getlayer(layer).statemachine; for (int i = 0; i < sm.statecount; i++) { unityeditorinternal.state state = sm.getstate(i); if (state.tag == tag) //change speed for all clip with the tag specified state.speed = speed; } } void setanimspeedwithclipname(int layer, string name, float speed) { unityeditorinternal.animatorcontroller ac = animator.runtimeanimatorcontroller as unityeditorinternal.animatorcontroller; unityeditorinternal.statemachine sm = ac.getlayer(layer).statemachine; for (int i = 0; i < sm.statecount; i++) { unityeditorinternal.state state = sm.getstate(i); if (state.uniquename == name) //change speed for only the clip name specified state.speed = speed; } } void setanimspeedoflayer(int layer, float speed) { unityeditorinternal.animatorcontroller ac = animator.runtimeanimatorcontroller as unityeditorinternal.animatorcontroller; unityeditorinternal.statemachine sm = ac.getlayer(layer).statemachine; for (int i = 0; i < sm.statecount; i++) { //change speed for all animation state in the layer unityeditorinternal.state state = sm.getstate(i); state.speed = speed; } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯