统一3D反向动画 [英] Reverse animation in unity 3D

查看:113
本文介绍了统一3D反向动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有动画的FBX对象.该对象是带有用于打开的动画的框.我想做的是,当用户单击一个按钮时,该框将打开(播放打开的动画),而当再次单击该按钮时,该框将关闭(向后播放打开的动画).

I have an FBX object with animation. The object is a box with animation for opening. What I'm trying to do is when the user clicks a button the box will open (play open animation) and when the button is clicked again the box will close (play open animation backwards).

正在播放开始动画时,我再次单击按钮,开始动画停止,并且框开始关闭,效果很好. 问题在于,当动画完成(打开)然后单击按钮关闭时,动画没有播放,它只是跳到没有动画的关闭框中.

While the opening animation is playing and I click the button again the opening animation stops and the box starts to close, that works fine. The problem is that when the animation is finished (open) and then I click the button to close, the animation is not playing and it just jumps to a closed box without animation.

这是我的代码:

public class ClickBtn : MonoBehaviour {

    public GameObject box = null;
    bool reverse = false;

    private void OnMouseDown()
    {
        Debug.Log(reverse);

        if (!reverse)
        {
            box.animation["Take 001"].speed = 1;
        }
        else
        {
            box.animation["Take 001"].speed = -1;
        }

        reverse = !reverse;

        box.animation.Play("Take 001");
    }
}

推荐答案

您的animation.WrapMode设置错误(可能是WrapMode.Once,这是默认设置).您可以使用:

your animation.WrapMode is set wrong (probably WrapMode.Once, which is default). In your case you could use:

WrapMode.PingPong:乒乓球在开始和结束之间来回移动.

animation.wrapMode = WrapMode.PingPong;

请介意,您不需要

box.animation["Take 001"].speed = -1;

现在,这是自动完成的.

anymore, this is done automatically.

这篇关于统一3D反向动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆