How to make Input.GetAxis(“Mouse X”) get a value even when the mouse is stopped?

I’m controlling a game object using my mouse horizontally. The object moves left or right depending on the mouse position but as soon as the mouse stops moving the object stops too. What I want is if I drag the mouse to the right side of the screen and stop moving the mouse, then I want the object to move to the right as long as the mouse is in the right half of the screen and vice versa. Currently Input.GetAxis(“Mouse X”); returns a 0 value when stopped. Here’s the code:

float horizontalInput = Input.GetAxis("Mouse X");

I’ve already tried using this fix but I don’t get the desired result as I’m using mousebuttondown to move my player in the forward direction.

if (Input.GetMouseButton(0) && (horizontalInput == 0f))
        {
            if (Input.mousePosition.x < Screen.width / 2)
            {

                horizontalInput = -1f;  
            }
            else if (Input.mousePosition.x > Screen.width / 2)
            {

                horizontalInput = 1f;
            }

         }

Is there any other way I can achieve this? Thank you so much for your time!

It’s (horizontalInput == 0f)that’s stopping it because you’re altering the variable you’re checking, also you don’t need the brackets round it.