在我的代码中,玩家只应该跳一次。但是玩家跳了起来,并且“IsGrounded”我仍然是真的,直到玩家再次跳起来。有人可以帮忙吗?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player_controller : MonoBehaviour {
public int speed = 5;
public Vector3 jump;
public int jumpForce = 2;
public bool isGrounded;
Rigidbody rb;
private string JumpButton = "Jump";
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
// Update is called once per frame
void Update () {
transform.Translate(speed * Input.GetAxis("Vertical") * Time.deltaTime, 0f, speed * Input.GetAxis("Horizontal") * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
isGrounded = false;
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
}
}
}