代码之家  ›  专栏  ›  技术社区  ›  wyskoj

如果上一个动画播放时间不够,Unity动画将无法播放

  •  0
  • wyskoj  · 技术社区  · 6 年前

    for (int i = 0; i < times.Length; i++) { // For each note
             bool notePlayed = false;
             while (!notePlayed) { // While current note hasn't been played (waiting for its time)
                 if (Time.timeSinceLevelLoad >= timesAdjusted [i]) { // If the current time is past or equal to the time it should play
                     anim.Play ("hit"); // Play animation
                     Debug.Log ("hit!");
                     notePlayed = true; // The note has been played.
                 }
                 yield return null;
             }
         }
    

    这是可行的,但前提是前一个音符和当前音符之间的时间足够长,动画才能完成。那么,无论动画是否完成,我如何才能让动画播放?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Hesamom    6 年前

    您正在使用“播放”方法,该方法将播放动画状态,而不考虑转换(空闲->命中),此外,在转换中未定义任何条件,将在状态之间创建无限循环。

    要解决主要问题,必须将“normalizedTime”参数设置为0,如:

    anim.Play ("hit",0,0); //assuming "hit" state is in your 0 layer
    
        2
  •  0
  •   auslander    6 年前

    禁用“有退出时间”复选框可更改动画而不等待其他动画