【问题标题】:Same animation for objects one after another一个接一个对象的相同动画
【发布时间】:2020-03-29 07:04:56
【问题描述】:

我的菜单中有一些按钮,它们都有相同的动画。我想在最后一个按钮动画开始播放后大约 50 毫秒播放每个按钮的动画。我怎么能这样做?

【问题讨论】:

    标签: unity3d animation


    【解决方案1】:

    我不知道你的设置是什么样的以及你是如何开始动画的。

    但是,假设您有一个按钮脚本 YourButtonScript 和一个方法 StartAnimation 您可以在 Coroutine 中执行此操作,例如

    // reference all your buttons in the Inspector via drag&drop
    public YourButtonScript[] buttons;
    
    public void StartAnimations()
    {
        // Starts the Coroutine
        StartCoroutine(AnimationsRoutine());
    }
    
    private IEnumerator AnimationsRoutine()
    {
        foreach(var button in buttons)
        {
            // however you start the animation on one object
            button.StartAnimation();
    
            // now wait for 50ms
            // yield tells the routine to "pause" here
            // let the frame be rendered and continue
            // from this point in the next frame
            yield return new WaitForSeconds(0.05f);
        }
    }
    

    Unity 中的协程就像临时的小Update 方法。通过使用默认的yield return null,您可以告诉 Unity 在此时离开 Ienumerator,渲染帧并继续下一帧。然后有一堆有用的工具可以让您yield 直到满足某个条件,如本例中的WaitForSecondsWaitForSecondsRealtime

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2012-02-12
      相关资源
      最近更新 更多