【发布时间】:2021-08-23 23:17:57
【问题描述】:
我真的只是一个初学者,我不知道如何在 Unity 中正确使用动画。我正在开发一款 2D 平台游戏。我设法使动画工作,但重点是我的角色应该从每一侧看起来都不同(所以我不能只是翻转精灵)。最简单的方法是什么,例如,当按右时,他将使用动画 1,而当按左时,他将使用动画 2?在此先感谢并为我的愚蠢感到抱歉;)
【问题讨论】:
标签: animation sprite directions animator
我真的只是一个初学者,我不知道如何在 Unity 中正确使用动画。我正在开发一款 2D 平台游戏。我设法使动画工作,但重点是我的角色应该从每一侧看起来都不同(所以我不能只是翻转精灵)。最简单的方法是什么,例如,当按右时,他将使用动画 1,而当按左时,他将使用动画 2?在此先感谢并为我的愚蠢感到抱歉;)
【问题讨论】:
标签: animation sprite directions animator
您是否尝试过使用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);
}
}
}
享受吧!
【讨论】: