Mashing Jump lets player jump twice

I’m having an issue where if the player mashes the jump button fast enough, they get an extra jump.

I’m pretty sure it has to do with my implementation of coyote time, but I’m not sure how I could change it to fix this issue.

Here’s the code I’m using for movement.

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

public class Movement : MonoBehaviour
{

    [Header("Movement")]    
    public float Speed;
    private Rigidbody2D RB;


    [Header("Jumping")]
    public float JumpHeight;
    private bool Jumping;
    private float Delay;
    public float HangTime;
    private float HangCount;
    public float JumpBufferLength;
    private float JumpBufferCount;
    public LayerMask GroundLayer;
    private bool IsGrounded;
    public Transform GroundCheck;

    [Header("Misc")]
    public Animator Anim;
    private bool Flipped;

    // Start is called before the first frame update
    void Start()
    {
        RB = gameObject.GetComponent<Rigidbody2D>();
        Anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        //Move
        if(Input.GetAxisRaw("Horizontal") != 0)
        {
            RB.velocity = new Vector2(Speed * Input.GetAxisRaw("Horizontal"), RB.velocity.y);
            Anim.SetBool("Walking", true);
        }
        else
        {
            RB.velocity = new Vector2(0, RB.velocity.y);
            Anim.SetBool("Walking", false);
        }

        //Check if player is grounded
        IsGrounded = Physics2D.OverlapCircle(GroundCheck.position, 0.1f, GroundLayer);

        if(RB.velocity.y < 0)
        {
            Anim.SetBool("Falling", true);
        }
        else
        {
            Anim.SetBool("Falling", false);
        }
        if (RB.velocity.y > 0)
        {
            Anim.SetBool("Jumping", true);
        }
        else
        {
            Anim.SetBool("Jumping", false);
        }


        //Coyote Jump
        if (IsGrounded == true)
        {
            HangCount = HangTime;
        }
        else if(IsGrounded == false)
        {
            HangCount -= Time.deltaTime;
        }

        //Jump Buffer
        if (Input.GetButtonDown("Jump"))
        {
            JumpBufferCount = JumpBufferLength;
        }
        else
        {
            JumpBufferCount -= Time.deltaTime;
        }

        if(Delay > 0)
        {
            Delay -= Time.deltaTime;
        }

        //Jump
        if (JumpBufferCount >= 0 && HangCount > 0)
        {
            RB.velocity = new Vector2(RB.velocity.x, JumpHeight);
            FindObjectOfType<AudioManager>().Play("Jump");
            HangCount = 0;
            JumpBufferCount = 0;
        }
        if(Input.GetButtonUp("Jump") && RB.velocity.y > 0)
        {
            RB.velocity = new Vector2(RB.velocity.x, RB.velocity.y * 0.5f);
        }

        //flip Character
        if(Input.GetAxisRaw("Horizontal") > 0 && Flipped == true)
        {
            gameObject.transform.localScale = new Vector3(-gameObject.transform.localScale.x, gameObject.transform.localScale.y, gameObject.transform.localScale.z);
            Flipped = false;
        }
        if (Input.GetAxisRaw("Horizontal") < 0 && Flipped == false)
        {
            gameObject.transform.localScale = new Vector3(-gameObject.transform.localScale.x, gameObject.transform.localScale.y, gameObject.transform.localScale.z);
            Flipped = true;
        }
    }
}

It looks like the culprit is line 105. If you release the jump button right around the peak of the jump, you would get a double jump at half the speed.

I would suggest using Input.GetButton to move the player up with RB.velocity.y as long as the button is held or until a jump timer runs out.

if (Input.GetButton("Jump") && jumpTime > 0)
{
    RB.velocity.y += jumpSpeed;
    jumpTime -= Time.deltaTime;
}

// Reset jumpTime when onGround is true

This way if the button is held down for the whole time you get max jump height, or when the player releases the button, they can do a shorter jump.