uGUI Button - Continuous Actions?

Hi All,

I’m doing some touch input for a sample phone game starter kit. I’m having some trouble with the buttons for run/jump. Its a simple platformer, you can run and jump, that’s it.

When you press run, it moves the rigidbody’s position (so you can have physics + player input). Anyways, if I push and hold the button, the character moves only per a single event click. I am trying to get it so that when you push and hold the button the character gets the nice smooth continuous motion just like when I call Input.getAxis(“Run”).

Any ideas on how to accomplish this?

Thanks,
~David

implement IPointerDownHandler interface in your button:

void IPointerDownHandler.OnPointerDown(PointerEventData eventData) {

    StartCoroutine(DoPress());
}

void IPointerUpHandler.OnPointerUp(PointerEventData eventData) {

    StopCoroutine(DoPress());
}

private IEnumerator DoPress() {

    while (true) {

        //move the player here
        yield return 0;
    }
}