2016-06-08 83 views
1

因此,在Unity中,我有一个简单的脚本来检测天气或不是播放器按W或S,如果他们这样做,然后播放步行动画。它的工作原理很好,但如果我停止移动,并且动画是通过播放的一半,我按下W或S,它会从动画的开始处重新开始动画,而不是当前停止的点,有没有办法使从那个时候玩,这里是代码:Unity C# - 从停止点开始继续播放动画

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(); 
    } 

回答

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; 
    } 
+0

这看起来并不像它会在工作两个键被按下的情况,或者当我让我的两个键之一走的情况。我不得不放开这两个键,然后重新按一个键移回。 – ps2goat

+0

对我而言它有效 –