uinity Animator 和Animation的正播,捯播,暂停动画实现方法(测试)

来源:互联网 发布:被网络诈骗了怎么办 编辑:程序博客网 时间:2024/05/14 14:28

首先要获得AnimationClip 对象, 点出来speed,当speed = 1.0f 正播动画,speed = -1的时候捯播动画,捯播的时候要先把normalizedTime  = 1.0f;

暂停只要使speed = 0;



using UnityEngine;

using System.Collections;


public class animPlay : MonoBehaviour {


public bool canBackward;//是否需要捯播
private int playCount = 0;
private bool hasPlay = false;
public string clip;

public void OnClick()
{
if (!animation.isPlaying) 
{
if(playCount==0)
{
animation[clip].speed = 1;
playCount++;
animation.Play ();
hasPlay = true;
Debug.Log("开始正播放动画");
}
else if(canBackward)
{
animation[clip].normalizedTime = 1.0f;
animation[clip].speed = -1;
playCount--;
animation.Play ();
Debug.Log("开始倒到播放动画");
}


}


}


}


Animator 使用暂停的时候要截断所有对象变量数值的改变,当变量改变的时候即使speed =0  还是要播动画的。

当你的动画正播到一半,未结束的时候想要倒播动画,直接可以把速度speed = -1 就可以了。

0 1
原创粉丝点击