仅需短短几行代码就可实现,效果如图
1.准备一个带动画的模型
2.一个slider组件
3.接下来上代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Animat : MonoBehaviour
{
public Animator planeAnimator;
public Slider slider;
AnimatorStateInfo stateInfo;
private void Start()
{
planeAnimator.speed = 0;
slider.onValueChanged.AddListener(OnSliderValueChange);
stateInfo = planeAnimator.GetCurrentAnimatorStateInfo(0);
}
public void OnSliderValueChange(float i)
{
planeAnimator.Play(stateInfo.fullPathHash, 0, slider.value);
}
}
4.把代码挂载到任意位置,把带动画的模型托到 planeAnimator,把滑动条组件拖到 slider
5.把动画的speed设置为0,不然开始运行 他自己就跑了,追都追不回来的那种!
6.完成!
@Liam:有用→收藏→关注