holding UI button

69064-button-script.png

i need help. i have an ui button and if i pressed that button, my player will move up. that is works but, the player just move up once. how to hold an ui button and my player will move up while pressing the button?

my PlayerMoveUp function:

	public void PlayerMoveUp(){
		transform.Translate(Vector2.up *Time.deltaTime);
}

Thanks

Add a script to the button which captures the OnPointerDown event from the button.

Use this interface to switch a flag (boolean) to enable a function to fire from Update.

void Update()
{
    if(myFlag)
    {
        FireFunction();
    }
}

Capture the OnPointerUp event to stop the function.