Question by
MrAwesome343 · Jun 18, 2016 at 07:31 PM ·
uimovementbuttonmobileevent triggering
Move the player by holding a UI Button?
I'm trying to make it so you can move the player with a UI Button, but it will only work for every time I press the button. How can I make is so the player moves WHILE I press the button, not WHEN I press the button? I also have an event trigger with Update Selected attached to the button.
public float speed;
public void moveRight()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
float moveRight = (Time.deltaTime * speed);
transform.Translate(moveRight, 0, 0);
break;
case TouchPhase.Ended:
transform.Translate(0, 0, 0);
break;
}
}
Comment