Recently, I’ve encountered a problem with player movement on android mobile device. It only seems to occur on android, since Unity Editor handles it perfectly “out of the box.”
When I click a button on my android device it doesn’t do the action it is supposed to do - make player go forward. When I touch other part of the screen and simultaneously (or after, while still holding other part of the screen) hold the button for going forward, it works fine.
The button is placed on a Canvas and has an additional script component added to it with OnPointerUp and OnPointerDown (which handles all of the movement setting the walking flag to true/false.)
Since all of the movement is based on IPointerDownHandler and IPointerUpHandler, I guess OnPointerDown is working fine itself. But why only if I’m touching other part of the screen with another finger?
P.S. OnBeginDrag works fine as well
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
public class ControlBehavior : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
public GameObject player;
// Use this for initialization
void Start () {}
// Update is called once per frame
void Update () {}
public void OnPointerDown (PointerEventData eventData) {
player.SendMessage ("up_pressed", 0, SendMessageOptions.DontRequireReceiver);
}
public void OnPointerUp (PointerEventData eventData) {
player.SendMessage ("up_released", 0, SendMessageOptions.DontRequireReceiver);
}
}