How do i double jump in this code

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;

void Start()
{
    
}

void Update()
{
    Jump();
    Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
    transform.position += movement * Time.deltaTime * moveSpeed;
}

void Jump()
{
    if (Input.GetButtonDown("Jump"))
	{
        gameObject.GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse);

    }
}

}

Don’t know about double jumping, I think it should work if the first jump works.

But you can’t mix setting the transform and AddForce… Either you let the physics engine move your RigidBody with AddForce or rb.velocity. Or you set the position. They will interfere with each other.

private const int c_MaxJumpCount = 2;
private Rigidbody2D rigid;
private bool isJumpPressed;
private int currentJumpCount;

public float jumpPower;


private void Awake()
{
  rigid = GetComponent<Rigidbody2D>();
}
 private void Update()
 {
      if (Input.GetButtonDown("Jump")) isJumpPressed = true;
 }

private void FixedUpdate()
{
   if(isJumpPressed) Jump();
}
 void Jump()
 {
         if(currentJumpCount < c_MaxJumpCount)
         {
                   rigid.velocity = new Vector3(0,0,0);
                   rigid.AddForce(new Vector2(0f, jumpPower), ForceMode2D.Impulse);
                   currentJumpCount++;       
         }    
    isJumpPressed = false;
 }

private void OnCollisionEnter2D(Collision collision)
{
  if(collision.collider.tag == "Ground") currentJumpCount = 0;

}