// 按W键,向上移动 if (Input.GetKey(KeyCode.W)) { Vector3 e_rot = transform.eulerAngles; e_rot.x = -90; e_rot.y = 0; e_rot.z = 0; transform.eulerAngles = e_rot; transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self); } // 按S键,向下移动 else if (Input.GetKey(KeyCode.S)) { Vector3 eulerAngles = transform.eulerAngles; eulerAngles.x = 90; eulerAngles.y = 0; eulerAngles.z = 180; transform.eulerAngles = eulerAngles; transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self); } // 按A键,向左移动 else if (Input.GetKey(KeyCode.A)) { Vector3 eulerAngles = transform.eulerAngles; eulerAngles.x = 0; eulerAngles.y = -90; eulerAngles.z = 90; transform.eulerAngles = eulerAngles; transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self); } // 按D键,向右移动 else if (Input.GetKey(KeyCode.D)) { Vector3 eulerAngles = transform.eulerAngles; eulerAngles.x = 0; eulerAngles.y = 90; eulerAngles.z = -90; transform.eulerAngles = eulerAngles; transform.Translate(Vector3.forward * Time.deltaTime * speed, Space.Self); }