Why this double jump script doesn't work?

Hello! I’m struggling to integrate a double jump script to my mobile game, but it doesn’t work the way it should. So I have created a UI image, that acts like a jump button and it consist of following script:

using UnityEngine;
using UnityEngine.EventSystems;

public class JoyButtonScript : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
    [HideInInspector]public bool jumpPressed;

    public void OnPointerDown(PointerEventData eventData){
        jumpPressed = true;
    }
    public void OnPointerUp(PointerEventData eventData){
        jumpPressed = false;
    }
 
}

Also I have PlayerMovement script attached to my player(script is down below). feetPos is a gameObject attached to player’s feets, to detect if player is grounded && whatIsGround is just LayerMask that is attached to my ground textures

private int jumpCount = 0;
void Update(){
onGround = Physics2D.OverlapCircle(feetPos.position, checkCircle, whatIsGround);

        if(onGround == true){
            jumpCount = 0;
        }
 
        if((Input.GetKeyDown(KeyCode.Space) || JoyButtonScript.jumpPressed) && onGround && jumpCount == 0){
           Jump();
           JumpEffect();
           jumpCount = 1;
       }else if((Input.GetKeyDown(KeyCode.Space)|| JoyButtonScript.jumpPressed) && onGround == false && jumpCount == 1){
           Jump();
           jumpCount = 0;
}
}

 void Jump(){
        rb.velocity = Vector2.up * jumpSpeed;
    }

“It doesn’t work the way it should” isn’t the most helpful description. What doesn’t work? Does it jump at all? Does it not do the second jump?

This seems to be the exact same question you asked here yesterday:

Did you even read my response? Did you even make the slightest attempt to find out what code is running? I gave you very specific steps to approach and understand the problem in the other thread linked above and yet you seem to have simply ignored it. Are you trying to help yourself or just hoping someone else will write it for you if you keep asking the same question again and again?

It jumps once, but doesn’t do second jump

Find why!! This is up to you. We CANNOT do it here.

Any errors in the console?

Is the code to read input still running? (put in a Debug.Log() and find out!)

Is the input being read properly?(put in a Debug.Log() and find out!)

If it is being read, what conditions are preventing the jump code?(put in a Debug.Log() and find out!)

If the jump code is running, why is the thing not jumping??(put in a Debug.Log() and find out!)

You have to work through this stuff yourself: we don’t have your project in front of us and we don’t want it.

The likely culprit is that you’re being set to grounded, resetting your jump count to 0, the very next frame in between physics ticks. You should process your input in Update() but the actual physics elements in FixedUpdate().