Player not jumping in uniform height

void Update () {
groundcheck = Physics2D.Raycast(transform.position,-Vector2.up,1f);
if(groundcheck.collider != null){
rigidbody2D.AddForce(force*Vector3.up);
}
}

I’m making an infinite jumping game and putting the above code to the character. The player jumps but its jumping inconsistently, sometimes too high and sometimes not jumping at all. what to do?

void Update () {
groundcheck = Physics2D.Raycast(transform.position,-Vector2.up,1f);
if(groundcheck.collider != null){
rigidbody2D.velocity.y = force;
}
}

Use velocity instead AddForce