【发布时间】:2019-07-31 23:10:28
【问题描述】:
我在 Unity 2018.4 中延迟我的角色移动时遇到了困难,我怀疑这更像是我的代码与 unity 相对的问题。
编辑: 我希望能够按住右箭头键,让角色415ms不动,然后能够移动580ms,之后他不能移动350ms(让动画播放完毕)
我尝试在 IE 分子中使用倒计时等待然后调用我的移动函数,但这会导致我的角色在动画播放后不移动。
//What makes the character move, works fine if executed on its own in update
private void ExecuteMovement(float dir)
{
currentPosition = transform.position;
currentPosition.x += dir * Time.deltaTime * speed;
transform.position = currentPosition;
}
//Trying to use waitforseconds to delay the execution while the animation plays
private IEnumerator Movement(float dir)
{
yield return new WaitForSeconds(0.5f);
ExecuteMovement(dir);
}
void Update()
{
if (0 > Input.GetAxis("Horizontal"))
{
//This is to flip image
transform.eulerAngles = new Vector3(0, 180, 0);
//starts animation
animator.SetBool("isSkipping", true);
//calls the movement function with the direction to move in
Movement(Input.GetAxis("Horizontal"));
}
else if (0 < Input.GetAxis("Horizontal"))
{
//This is to flip image
transform.eulerAngles = new Vector3(0, 0, 0);
//starts animation
animator.SetBool("isSkipping", true);
//calls the movement function with the direction to move in
Movement(Input.GetAxis("Horizontal"));
}
}
我很乐意尝试任何其他方法来延迟角色的移动。动画显示角色充电跳跃然后跳跃。我只想在动画大约半秒后在空中移动。
【问题讨论】: