How Can I Decrease Springjoint2D Distance Over Time?

I imagine this is a new-coder problem, but I have a script set up where when I hold the space bar, the distance in a 2D Spring Joint is supposed to decrease over time. The issue is that the distance only decreases for the first frame. Here is the code I have set up:

        if (joint != null && Input.GetButtonDown("Jump"))
        {
            joint.distance -= Time.deltaTime * 0.2f;
        }

The logic is that when the spring joint (joint) exists, or is not null and when Jump is being pressed, then the joint distance decreases. Any help would be appreciated!

GetButtonDown is only called when you first depress the key, so it will only happen on the first frame that you hold it down. If you use GetButton instead, this will be true on every frame that the key is held down.

Assuming your code above is inside of update it should work. You might have issues when the distance gets lower than zero though, but I haven’t tested that.