using System.Collections;
using System.Collections.Generic;
public class Movement : MonoBehaviour
public Transform groundCheckTransform;
private bool jumpKeyWasPressed;
private float horizontalInput;
private Rigidbody rigidbodyComponent;
private int jumpCount = 2;
rigidbodyComponent = GetComponent<Rigidbody>();
if (Input.GetKeyDown(KeyCode.Space))
jumpKeyWasPressed = true;
horizontalInput = Input.GetAxis("Horizontal");
private void FixedUpdate()
if (Physics.OverlapSphere(groundCheckTransform.position, 0.1f).Length == 1)
else if(jumpKeyWasPressed && jumpCount >= 0)
Debug.Log("Im in the air " + jumpCount);
rigidbodyComponent.AddForce(Vector3.up * 5, ForceMode.VelocityChange);
jumpKeyWasPressed = false;
rigidbodyComponent.velocity = new Vector3(horizontalInput *2, rigidbodyComponent.velocity.y,0);