如何从空格键添加跳转功能。目前,我具有按“ d”和“ q”的左右功能。我尝试了一个在线发现的功能,但似乎无法正常使用。任何帮助将不胜感激。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player_movement : MonoBehaviour {
public Rigidbody rb;
public float sideway_force = 100f;
float forward_force = 1000f;
// Update is called once per frame
void FixedUpdate () {
rb.AddForce(0, 0, forward_force * Time.deltaTime);
if (Input.GetKey("d")) {
rb.AddForce(sideway_force * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("q")) {
rb.AddForce(-sideway_force * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
这是我尝试过的代码。:
if (Input.GetKeyDown("space"))
{
transform.Translate(Vector3.up * 90 * Time.deltaTime, Space.World);
}