Unity C# - 如何从停止的角度继续播放动画

时间:2016-06-08 22:13:04

标签: c# unity3d

所以在Unity中我有一个简单的脚本来检测天气与否,玩家按下W或S,如果他们这样做,则播放一个步行动画。并且它工作正常,但如果我停止移动并且动画是播放的一半而我按W或S它将从动画的开头重新开始动画而不是它停止的当前点,是否有办法从那一点开始玩,这是代码:

    if (Input.GetKey(KeyCode.W))
    {
        animation.Play("Walking");
    }

    if (Input.GetKey(KeyCode.S))
    {
        animation.Play("Walking");
    }

    if (Input.GetKeyUp(KeyCode.W))
    {
        animation.Stop();
    }

    if (Input.GetKeyUp(KeyCode.S))
    {
        animation.Stop();
    }

1 个答案:

答案 0 :(得分:0)

我只是改变速度而不是使用开始和停止:

    animation.Play();
    if (Input.GetKey(KeyCode.W))
    {
        animation["Walking"].speed = 1;
    }

    if (Input.GetKey(KeyCode.S))
    {
        animation["Walking"].speed = -1;
    }

    if (Input.GetKeyUp(KeyCode.W))
    {
        animation["Walking"].speed = 0;
    }

    if (Input.GetKeyUp(KeyCode.S))
    {
        animation["Walking"].speed = 0;
    }