[英]Unity 5 mecanim animation controlled by UI slider
I'm trying to get a slider to control an animation in my scene. 我试图获得一个滑块来控制场景中的动画。 I need to the length of the slider to match the length of the animation and when I scrub the slider, the animation should play the appropriate part.
我需要滑块的长度与动画的长度相匹配,并且当我滑动滑块时,动画应该扮演适当的角色。
public Slider slider;
public Animator animator;
void Start()
{
slider.onValueChanged.AddListener(OnValueChanged);
}
private void OnValueChanged(float changedValue)
{
animator.speed = 0;
animator.Play("yourAnimationName", -1, slider.normalizedValue);
}
I have also placed this on my slider components on value changed section but the two still do not synch up. 我也将其放置在值更改部分的滑块组件上,但两者仍未同步。 What is it I'm doing wrong / missing?
我做错了什么/想念什么?
edit updated code sample and removed the error 编辑更新的代码示例并消除错误
Error is quite clear about it. 错误非常清楚。 Delegate has to have float parameter.
委托必须具有float参数。 Change
更改
private void OnValueChanged()
to 至
private void OnValueChanged(float changedValue)
Update: 更新:
Don't set the animation speed to 0: 不要将动画速度设置为0:
public Slider slider;
public Animator animator;
void Start()
{
animator.speed = 0.00001f;
slider.onValueChanged.AddListener(OnValueChanged);
}
private void OnValueChanged(float changedValue)
{
animator.speed = 0.00001f;
animator.Play("yourAnimationName", -1, slider.normalizedValue);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.