【发布时间】:2016-08-29 04:22:14
【问题描述】:
我正在尝试让“播放此动画时玩家无法移动”检查我的移动方法。
我有一个 3x8 网格的面板用于此应用程序,播放器在面板之间移动。为此,我有 2 个动画:当玩家离开面板时播放 MovingOut,当玩家进入面板时播放“MovingIn”。所以我想要的流程是:
玩家按下移动键→移动被禁用→“MovingOut”播放→播放器的transform.position移动到目标位置→“MovingIn”播放→重新启用移动。
每个动画只有 4 帧。我目前在“MovingOut”的开头有一个动画事件,它将 int CanMove 设置为 0,在“MovingIn”的末尾有另一个动画事件,将 CanMove 设置为 1。
到目前为止,我的代码如下所示:
public void Move(int CanMove)
{
//this lets me use panelManager to access methods in the PanelManager script.
panelManager = GameObject.FindObjectOfType(typeof(PanelManager)) as PanelManager;
animator = GetComponent<Animator>();
if (Input.GetAxisRaw("Horizontal") == 1 && CanMove == 1) //go right
{
movingToPanel += 1;
if (IsValidPanel(movingToPanel))
{
//play animation MovingOut
animator.Play("MovingOut");
transform.position = panelManager.GetPanelPos(onPanel + 1);
onPanel += 1;
}
else
{
movingToPanel -= 1;
}
}
//else if( ...the rest of the inputs for up/down/left are below.
}
我在动画制作器中设置了 MovingIn,以便它在 MovingOut 动画结束时播放,这就是我不在脚本中调用它的原因:
我一生都无法弄清楚如何将 CanMove 传递到方法中,而不必在调用方法时强制定义它。目前我有 Move(1);在我的 Update() 方法中被调用只是为了检查移动是否正常(除了我遇到的这个问题)并且它的工作原理是我可以将面板移动到面板,但是由于 CanMove 在更新中被定义为 1函数,动画的事件不会阻止运动。
任何见解将不胜感激!
【问题讨论】: