【问题标题】:Animate buttons (slide left, slide right, slide down) in unity3d v4.6unity3d v4.6 中的动画按钮(向左滑动、向右滑动、向下滑动)
【发布时间】:2014-12-23 08:45:38
【问题描述】:

在实例化按钮并将它们添加到场景中时,我需要执行某种动画,因此它们会通过向下滑动动画(或向左或向右滑动)添加到场景中。 到目前为止我的代码:

for (int i = 0; i < 4; i++) {
        // Instantiate 4 buttons
        Transform clone =  (Transform)Instantiate (suggestionBtn, 
                                               new Vector3 (4, y, 0), Quaternion.identity);
        // make instance the child of the canvas
        clone.SetParent(gameObject.transform, false); 
        clone.transform.rotation = transform.localRotation;
        y -= 70;
}

我不确定我是否需要制作动画文件并将它们附加到我需要动画的每个按钮或使用像LeanTween 这样的引擎,或者只是几行代码可以确保向下滑动/向左滑动/滑动正确的动画?

【问题讨论】:

  • 很难,这是一个陈旧且过于复杂的脚本。您可能可以充分利用这个pastebin.com/18Xp09Ai 它有 4 个按钮的设置,每个按钮都有另外 4 个按钮。它向下滑动,然后向侧面滑动。 Itween 和 leantween 也是一个不错的选择。
  • 如果您不想使用第 3 方资源 (iTween),您可以创建自己的补间方法。在这里看一个类似的问题,看看我的回答stackoverflow.com/questions/27119906/…

标签: c# unity3d


【解决方案1】:

您可以使用iTween 来执行此操作:

static float y0;
static float FadeInOutTime = 1.0f;

//Called in Awake()
y0 = GameObject.Find("button_home").transform.position.y;

public static IEnumerator AnimateIn ()
{
    int i = 0;

    foreach (var item in ToolbarButtons) {
        var pos = item.transform.position;
        iTween.MoveTo(item, new Vector3(pos.x, y0 + 6, pos.z), FadeInOutTime);
        yield return new WaitForSeconds (i * 0.02f);
        i++;
    }
    yield return null;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多