How to move my object while the GUI button is being pressed?

Hi! I’m a beginner and I’m making my first game for android. I’ve my character and I’m using 3 buttons to move left, right and jump. I want to hold the button to move but onPointerDown() which I put on the buttons not working as I expected. Here is some code :

moving Left: which I’m triggering with onPointerDown() event on my button

 public  void movL()
    {
        ismov = true;
        if (ismov)
        {
            rb.velocity = Vector2.left * 2f;
        }
        else
        {
            rb.velocity = Vector2.zero;
        }
    }

stop moving, which I’m calling at onPointerup()

public void stopmov()
    {
        ismov = false;
    }

What I’m doing wrong?
Or Is there any other method to move while the button is being pressed like any other android game?

You shouldn’t have ismov being set within. That’ll cause the if statement to be true every time. Scope of Variables in C# - GeeksforGeeks

The problem is my character can walk normally with simple one click, but that’s not what I want. Like the keyboard I want him to walk as long as the key is being pressed. How to do that ??

Without looking at your code, all I can do is speculate. I’d do something like:

//Left pointer 
void moveLeft()
    {
           rb.velocity = Vector2.left;
    }

Then have moveLeft() called on button’s OnPointerDown event.

That’s what I did. he even moved but not continuously as I expected… That’s the thing