2d character jump when i release spacebar.

Hey,
I would like to use spacebar to let my character jump in the air, but i want to hold spacebar when the character is still on the ground, and then when i release spacebar, it jumps. the longer i hold spacebar, the higher i want my character to jump.

this is the code i have right now:

public float startTime = 0f;
    public float holdTime = 3.0f; // 3 seconds

if (Input.GetKey(KeyCode.Space))
        {
            startTime = Time.time;
            if (startTime >= holdTime && isGrounded)
            {
                Debug.Log("It Works Great!");
                r2d.velocity = new Vector2(r2d.velocity.x, jumpHeight);
            }

        }

the problem is: when space is held and it reaches the 3 seconds, it instantly goes up even when i am still holding spacebar. I only want it to go up when i release spacebar.
Any help is much appreciated!

There is GetKey(), GetKeyDown() and GetKeyUp(). Get key triggers if the button is held down. GetKeyDown triggers only the frame you press it, GetKeyUp triggers only the frame you release the button. So what you want to do is:
float timer=0;
if (Input.GetKeyDown(KeyCode.Space))
timer=0;
if (Input.GetKey(KeyCode.Space))
timer+=Time.deltaTime;
if (Input.GetKeyUp(KeyCode.Space))
r2d.velocity = new Vector2(r2d.velocity.x, jumpHeight*timer);