unity3d - 使用动画在 x 轴上移动对象
问题描述
我想用动画在 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;
}
}
解决方案
您可以简单地以统一的方式逐帧录制动画,然后在清醒时播放动画或使用脚本使用触发方法
推荐阅读
- python-3.x - 替换字符串字符的函数问题
- html - 从从 db 检索的对象数组中获取结果并返回到 ng-template
- angular - 动态角度复选框过滤器
- c# - Clickonce:applicationUri 为空,允许传递 URL 参数设置为 true
- python - Why i am getting this error keyword:Borough
- php - 管理每日创建的表以在数据表中显示数据
- java - 如何从 sqlite 获取数据,并使用 stackwidget 显示它?
- regex - RegEx 日期模式格式验证未按预期工作
- html - Override html input[type=number] styling for changing the arrows
- python-3.x - 如何绘制特定的数据框