我想用动画在x轴上移动游戏对象。我写了下面的代码,但只有在清除input.getkeydown条件后,它才有效。如果按下该键,有没有办法做到这一点? 谢谢
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
float delta = speed * Time.deltaTime;
Vector3 currentPosition = gameObject.transform.position;
Vector3 nextPosition = Vector3.MoveTowards(currentPosition, new Vector3(center, transform.position.y, transform.position.z), delta);
// Move the object to the next position
Debug.Log("delta" + delta);
Debug.Log("nextposition x" + nextPosition.x.ToString());
gameObject.transform.position = nextPosition;
}
}
答案 0 :(得分:0)
您可以简单地统一记录每个帧的动画帧,然后在唤醒时或使用脚本的触发方法播放动画