so i have been trying to make my rigidbody jump,problem is that it only jumps once then it won’t execute the action.
Here is the code
void Start () {
ground = true;
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.Space) && ground == true) {
rb.AddForce (Vector2.up * Jumpforce);
ground = false;
}
if (Input.GetKey (KeyCode.D)) {
rb.AddForce (Vector2.right * speed);
}
}
void OnCollision2DEnter(Collision2D col){
if (col.gameObject.tag == "Ground") {
ground = true;
}
}
void OnCollision2DExit(Collision2D coly){
if (coly.gameObject.tag != "Ground") {
ground = false;
}
}
}