- Home /
holding UI button
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
button-script.png
(15.9 kB)
Comment
Answer by meat5000 · Apr 29, 2016 at 07:58 AM
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.
Your answer
