I'm trying to make an InputBuffer for my jump

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AdultMovement2 : MonoBehaviour
{
    public Rigidbody2D rb;
    public float speed;
    public float jumpForce;
    private RaycastHit2D hit;
    public bool isGrounded;
    public LayerMask Floor;
    public float CoyoteTimeCounter;
    public float CoyoteTime;
    public float jumpBufferCounter;
    public float jumpBufferTime;
    // Start is called before the first frame update
    void Start()
    {
       
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        GroundCheck();  
        if (isGrounded==true)
        {
            CoyoteTimeCounter = CoyoteTime;
        }
        else
        {
            CoyoteTimeCounter -= Time.deltaTime;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            jumpBufferCounter = jumpBufferTime;
        }
        else
        {
            jumpBufferCounter -= Time.deltaTime;
        }
        if (CoyoteTimeCounter>0 && jumpBufferCounter>0)
        {
            Jump();
            jumpBufferCounter = 0;
        }
        
        
        
    }
    private void LateUpdate()
    {
        
    }
    public void GroundCheck()
    {
        float rayCastLengh = 0.45f;
        Ray2D ray = new Ray2D(transform.position, Vector2.down);
        Debug.DrawRay(ray.origin, ray.direction * rayCastLengh, Color.red);
        isGrounded = Physics2D.Raycast(ray.origin, ray.direction, rayCastLengh, Floor);
    }
    private void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            LeftMovement();
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            RightMovement();
        }
        

    }
    
    public void RightMovement()
    {
            Vector2 direction = new Vector2(1 * speed, rb.velocity.y);
            rb.velocity = direction;
    }
    public void LeftMovement()
    {
            Vector2 direction = new Vector2(-1 * speed, rb.velocity.y);
            rb.velocity = direction;
    }
    public void Jump()
    {
        rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
        
    }
}

It just doesn’t work. I press the “Space” before fall into the ground, but the player doesn’t jump.

Maybe this will help?
When the jump key is pressed during the CoyoteTime (the time window after leaving the ground), the character jumps instantly, which might not be the desired behavior. We can fix that by introducing a flag to check whether the jump key was pressed.

Here’s the modified code with the input buffer and the flag to control the jump:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AdultMovement2 : MonoBehaviour
{
    public Rigidbody2D rb;
    public float speed;
    public float jumpForce;
    private RaycastHit2D hit;
    public bool isGrounded;
    public LayerMask Floor;
    public float CoyoteTimeCounter;
    public float CoyoteTime;
    public float jumpBufferCounter;
    public float jumpBufferTime;
    private bool isJumpKeyPressed;

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        GroundCheck();
        if (isGrounded)
        {
            CoyoteTimeCounter = CoyoteTime;
        }
        else
        {
            CoyoteTimeCounter -= Time.deltaTime;
        }

        // Input buffer for jump
        if (Input.GetKeyDown(KeyCode.Space))
        {
            isJumpKeyPressed = true;
            jumpBufferCounter = jumpBufferTime;
        }
        else
        {
            isJumpKeyPressed = false;
            jumpBufferCounter -= Time.deltaTime;
        }

        if (CoyoteTimeCounter > 0 && isJumpKeyPressed && jumpBufferCounter > 0)
        {
            Jump();
            jumpBufferCounter = 0;
        }
    }

    public void GroundCheck()
    {
        float rayCastLength = 0.45f;
        Ray2D ray = new Ray2D(transform.position, Vector2.down);
        Debug.DrawRay(ray.origin, ray.direction * rayCastLength, Color.red);
        isGrounded = Physics2D.Raycast(ray.origin, ray.direction, rayCastLength, Floor);
    }

    private void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            LeftMovement();
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            RightMovement();
        }
    }

    public void RightMovement()
    {
        Vector2 direction = new Vector2(1 * speed, rb.velocity.y);
        rb.velocity = direction;
    }

    public void LeftMovement()
    {
        Vector2 direction = new Vector2(-1 * speed, rb.velocity.y);
        rb.velocity = direction;
    }

    public void Jump()
    {
        rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
    }
}

Sorry about that, maybe this will help? using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AdultMovement2 : MonoBehaviour
{
public Rigidbody2D rb;
public float speed;
public float jumpForce;
private RaycastHit2D hit;
public bool isGrounded;
public LayerMask Floor;
public float CoyoteTimeCounter;
public float CoyoteTime;
public float jumpBufferTime;
private bool isJumpKeyPressed;

// Start is called before the first frame update
void Start()
{
    rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    GroundCheck();
    if (isGrounded)
    {
        CoyoteTimeCounter = CoyoteTime;
    }
    else
    {
        CoyoteTimeCounter -= Time.deltaTime;
    }

    // Input buffer for jump
    if (Input.GetKeyDown(KeyCode.Space))
    {
        isJumpKeyPressed = true;
        StartCoroutine(JumpBuffer());
    }
}

IEnumerator JumpBuffer()
{
    float timer = jumpBufferTime;
    while (timer > 0f)
    {
        yield return null;
        timer -= Time.deltaTime;
    }
    if (CoyoteTimeCounter > 0 && isJumpKeyPressed)
    {
        Jump();
    }
    isJumpKeyPressed = false; // Reset the jump input after the buffer time
}

public void GroundCheck()
{
    float rayCastLength = 0.45f;
    Ray2D ray = new Ray2D(transform.position, Vector2.down);
    Debug.DrawRay(ray.origin, ray.direction * rayCastLength, Color.red);
    isGrounded = Physics2D.Raycast(ray.origin, ray.direction, rayCastLength, Floor);
}

private void FixedUpdate()
{
    if (Input.GetKey(KeyCode.LeftArrow))
    {
        LeftMovement();
    }
    if (Input.GetKey(KeyCode.RightArrow))
    {
        RightMovement();
    }
}

public void RightMovement()
{
    Vector2 direction = new Vector2(1 * speed, rb.velocity.y);
    rb.velocity = direction;
}

public void LeftMovement()
{
    Vector2 direction = new Vector2(-1 * speed, rb.velocity.y);
    rb.velocity = direction;
}

public void Jump()
{
    rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}

}