通过滑动Slider 来控制动画的进度 ,直接上代码
public const string ANIM_NAME = "Take001";
//模型对象
public GameObject obj;
public GameObject obj01;
//进度条
public float hSliderValue = 0.0f;
public float animLegth = 0.0f;
void Start()
{
//得到模型动画
//obj = GameObject.Find("man");
//obj01 = GameObject.Find("man01");
//得到动画播放长度
animLegth = obj.GetComponent<Animation>().GetClip("Take001").length;
//animation[ANIM_NAME].length;
}
void OnGUI()
{
//显示信息
string show = "CurrentAnimationLength" + hSliderValue.ToString() + "(s)" + "/" + animLegth.ToString() + "(s)";
GUILayout.Label(show);
//计算拖动条拖动数值
hSliderValue = GUILayout.HorizontalSlider(hSliderValue, 0.0f, 5.0f, GUILayout.Width(200));
//绘制动画帧
PlaysilderAnimation(obj, hSliderValue);
PlaysilderAnimation(obj01, hSliderValue);
}
public void PlaysilderAnimation(GameObject manObject, float times)
{
//播放动画
if (!manObject.GetComponent<Animation>().isPlaying)
{
// manObject.animation.Play(ANIM_NAME);
// manObject.GetComponent<Animation>().Play();
}
//设置动画时间
manObject.GetComponent<Animation>().clip.SampleAnimation(manObject, times);
}
}