【发布时间】:2018-01-04 02:31:13
【问题描述】:
我是 Unity 和 Stack Overflow 的新手,我一直在寻找可以让对象(如玩家)移动的脚本。我找到了一个可以工作的脚本,嗯,有点工作或按计划进行。当我测试脚本时,当我按下箭头键时,它不会前进,而是开始跳跃。如果我按下向下箭头键,立方体(或玩家)将尝试将自己推入地下,然后永远坠落,但左右箭头键工作得很好。请注意,此脚本目前仅用于移动播放器,没有其他用途,以防万一您认为它应该用于其他或不同的东西。代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
public float moveSpeed;
// Use this for initialization
void Start()
{
moveSpeed = 5f;
}
// Update is called once per frame
void Update()
{
transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime, 0f);
}
}
希望您能找到解决方案或找到解释。感谢您的回复。 问候, 用户:9104031
【问题讨论】: