time counter in scripting

is there any way to set a timer in unity?
I used Time.deltaTime:

jumpTimeCounter = jumpTimeCounter - Time.deltaTime;

In this function:

private void jump()
    {
        Debug.Log(Time.deltaTime);
        if(canJump == true && Input.GetKeyDown(KeyCode.Space) == true)
        {
            playerRb.velocity = Vector2.up * jumpForce;
            canJump = false;
        }

        if(Input.GetKey(KeyCode.Space) == true)
        {
            if(jumpTimeCounter > 0)
            {
                //mettere su anki speigazione di questo codice
                playerRb.velocity = new Vector2(playerRb.velocity.x, 0) + Vector2.up * jumpForce;
                jumpTimeCounter = jumpTimeCounter - Time.deltaTime;
            }
        }
        if(Input.GetKeyUp(KeyCode.Space))
                jumpTimeCounter = 0;
    }

But the player occasionally jumps to different heights.

This is the output of Debug.Log (Time.deltaTime):

178406-cattura.png

the whole class code is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControl : MonoBehaviour
{
    private Rigidbody2D playerRb;

    //variabili movimento orizontale
    public float speedHorizontal;
    private float horizontalInput;
    //variabili salto
    private bool canJump = false;
    public float jumpForce;
    public float jumpTimeCounter;
    public float maxJumpTime;

    private float defaultGravityScale;
    public float moltiplicatoreGravityScale;

    void Start()
    {
        playerRb = gameObject.GetComponent<Rigidbody2D>();

        defaultGravityScale = playerRb.gravityScale;
        moltiplicatoreGravityScale = moltiplicatoreGravityScale*playerRb.gravityScale;
        jumpTimeCounter = maxJumpTime;
    }

    // Update is called once per frame
    void Update()
    {       
        horizontalMove();
        jump();
    }

    void FixedUpdate()
    {
        if(playerRb.velocity.y < 0)
            playerRb.gravityScale = moltiplicatoreGravityScale;
        else
            playerRb.gravityScale = defaultGravityScale;
    }

    private void horizontalMove()
    {
        float horizontalInput = Input.GetAxis("Horizontal");
        playerRb.velocity = new Vector2(speedHorizontal * horizontalInput, playerRb.velocity.y);
    }

    private void jump()
    {
        Debug.Log(Time.deltaTime);
        if(canJump == true && Input.GetKeyDown(KeyCode.Space) == true)
        {
            playerRb.velocity = Vector2.up * jumpForce;
            canJump = false;
        }

        if(Input.GetKey(KeyCode.Space) == true)
        {
            if(jumpTimeCounter > 0)
            {
                //mettere su anki speigazione di questo codice
                playerRb.velocity = new Vector2(playerRb.velocity.x, 0) + Vector2.up * jumpForce;
                jumpTimeCounter = jumpTimeCounter - Time.deltaTime;
            }
        }
        if(Input.GetKeyUp(KeyCode.Space))
                jumpTimeCounter = 0;
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.tag == "Ground")
        {
            canJump = true;
            jumpTimeCounter = maxJumpTime;
        }
    }
}

Have you tried putting your jump() function into FixedUpdate()?

You should always listen for Inputs in Update and apply physics in FixedUpdate.

You could try something like:

void Update()
{
    if (Input.GetKeyUp(KeyCode.Space)
    {
        shouldJump = true;
    }
}

void FixedUpdate()
{
    if (shouldJump)
    {
        shouldJump = false;
        //do jump things
    }
}

You should always listen for Inputs in Update and apply physics in FixedUpdate.

You could try something like:

void Update()
{
    if (Input.GetKeyUp(KeyCode.Space)
    {
        shouldJump = true;
    }
}

void FixedUpdate()
{
    if (shouldJump)
    {
        shouldJump = false;
        //do jump things
    }
}