How to move an object using UI Button (Unity/ Android studio)

Hi

There is an object in the scene. There are two UI Buttons up & down in the scene. What I want, when user touches the up button, object should move forward and the moment user releases his finger (untouches the button) the object should stop. And I want same for down button to move the object backward.

Currently with the code

public void moveUp(){
rigidbody.position=new vector3(transform.position.x, transform.position.y, transform.position.z+5f);
}

I could able to move the object. But user has to continuous tap on the up button to move the object forward.

I want once user touches the up button, the object should move forward and the moment he releases it should stop. HOpe you understand my requirement.

What you need are Event Triggers.

Use OnPointerDown to detect when the user presses the button and use OnPointerUp to detect when the user releases the button.

You could create a bool that toggles its value based on whether the button is pressed or not and then use this bool to call your MoveUp() function.