Execute line of code every X seconds.

I’m trying to make a Super Jump in my platformer game. Depending on how long you press a key, the character should jump higher or lower.

private int timer = 3;
    public float JumpForcePS;
    private float PowerJump = 0;

private void Update()
{
        if (Input.GetKey(KeyCode.LeftShift) && IsGrounded)
        {
            if (timer > 0)
            {
                PowerJump += JumpForcePS;
                timer--;
              //Somehow make it wait 1 second before executing code again
            }
        }
        if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            rb.velocity = Vector2.up * PowerJump;
            timer = 3;
            PowerJump = 0;
        }
}

In my case PowerForcePS is 7. The problem here is that when pressing Left Shift PowerJump will always equal 21. I want so that if you press for 1 second it will equal 7, if it’s pressed for 2 seconds it will equal 14 and if it’s pressed for 3 seconds it will be 21. How do I execute the code in “if (Timer > 0)” every second instead of every frame?

you could have a variable that keeps track of the amount of time that has passed by using Time.deltaTime

float totalTime = 0;

private void Update()
{
    totalTime += Time.deltaTime;
    //your stuff
}

So maybe you can do something like this

if (totalTime => 1) //if totalTime is more than 1 second
// continue doing your stuff