Constant force?

Was wondering how would I make the movement constant? If put “newVelocity.x = maxSpeed;” below the if() statement it moves to the right until it hits an object which is what I want. If I put it in the if() statement it only plays once. Any idea how to make it move until it hits something while being activated by a button press?

    public float jump = 2;
    public float speed = 1;

    [SerializeField]
    Rigidbody2D rb;

    void FixedUpdate()
    {
        var newVelocity = rb.velocity;
        if (Input.GetMouseButtonUp(0))
            newVelocity.y = jump;

        newVelocity.x = speed;

        rb.velocity = newVelocity;
    }

@zeke-27 instead of doing that (which runs just in the next frame) on button down turn a bool “isWalking” to true and use it in the if statement on button up turn that bool to false this should fix your problem.

public float JumpSpeed = 2;
public float RunSpeed = 1;

 [SerializeField]
 Rigidbody2D rb;

private bool jumping;

 private Vector2 velocity;

 // Use Update to handle Inputs
 void Update()
 {
     if (Input.GetMouseButtonUp(0))
         jumping = true;
 }

 // Use FixedUpdate to handle Physics
 void FixedUpdate()
 {
     if( jumping )
     {
         velocity.Set( JumpSpeed, RunSpeed );
         jumping = false;
     }
     else
     {
          velocity.y = rb.velocity.y;
     }
     rb.velocity = velocity;
 }