【问题标题】:Different animation in 2 directions2个方向的不同动画
【发布时间】:2021-08-23 23:17:57
【问题描述】:

我真的只是一个初学者,我不知道如何在 Unity 中正确使用动画。我正在开发一款 2D 平台游戏。我设法使动画工作,但重点是我的角色应该从每一侧看起来都不同(所以我不能只是翻转精灵)。最简单的方法是什么,例如,当按右时,他将使用动画 1,而当按左时,他将使用动画 2?在此先感谢并为我的愚蠢感到抱歉;)

【问题讨论】:

    标签: animation sprite directions animator


    【解决方案1】:

    您是否尝试过使用Animator Controller

    [RequireComponent(typeof(Animator))]
    public class PlayerAnimation: MonoBehaviour
    {
        [SerializeField]private Animator _animator;
        private const string DirectionParam = "Direction";
        private void Update()
        {
            //On Right button clicked
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                //Play Right animation
                _animator.SetInteger(DirectionParam, 1);
            }else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                _animator.SetInteger(DirectionParam, -1);
            }
            else
            {
                _animator.SetInteger(DirectionParam, 0);
            }
        }
    }
    
    1. 将此脚本拖到您的播放器上。这还将在您的游戏对象上添加统一动画器组件。
    2. 创建动画对象并将其放置在动画组件上。
    3. 从 Window>Animation>Animator 打开 Animator Editor
    4. 然后在Animation Controller Window中创建一个int参数,命名为“Direction”。
    5. 创建两个动画剪辑,一个用于左移动画,另一个用于右移动画
    6. 将这些剪辑拖到动画窗口。右键单击并创建两个转换并使用 Direction 参数添加条件。您应该创建 3 个动画剪辑并将其设置为空闲,并在方向值为 0 时过渡到空闲。

    享受吧!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      相关资源
      最近更新 更多