private float speed = 5.0f;
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");//键盘控制游戏物体在水平面进行移动
if(Input.GetKeyDown(KeyCode.W))
{
transform.Translate(h*Time.deltaTime*speed,0, v * Time.deltaTime * speed);
}
if(Input.GetKeyDown(KeyCode.S))
{
transform.Translate(h * Time.deltaTime * speed, 0, v * Time.deltaTime * speed);
}
if (Input.GetKeyDown(KeyCode.A))
{
transform.Translate(h * Time.deltaTime * speed, 0, v * Time.deltaTime * speed);
}
if(Input.GetKeyDown(KeyCode.D))
{
transform.Translate(h * Time.deltaTime * speed, 0, v * Time.deltaTime * speed);
}
}
游戏物体水平移动
最新推荐文章于 2022-11-13 22:21:44 发布