Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Input problem on one Android phone but not the other.

Discussion in 'Android' started by yusefkerr, Nov 17, 2020.

  1. yusefkerr


    Apr 5, 2011
    Hello, I'm creating my first android project, which is a simple port of a tabletop card game from PC. I've recently started testing it on a Samsung s10e running Android 10. I'm using the new Unity Input system, and when I started to refactor my code to use touch input rather than mouse/keyboard, I realised that the new Input system doesn't work with Unity remote, which makes everything a bit harder.

    I've got to where I want with testing on the s10e, but I then decided to try it on a similar but older phone, a Samsung A3, running Android 8. There are a few things that aren't working correctly, and considering how similar the phones are, I'm surprised by some of these differences.

    One big issue is input. I've got the following input script (full script attached) that's supposed to differentiate between a double tap and single tap. The double tap works fine (it flips a card over), but the single tap does nothing (when the co-routine ends, it's supposed to flip a boolean to say that the touch is held down, and then code in the Update() function changes the position of the selected card to follow the pointer screen position).

    Code (CSharp):
    1.  public void OnPointerDown(PointerEventData eventData)
    2.     {
    3.         tap++;
    4.         float timeSinceLastClick = Time.unscaledTime - savedClickTime;//Note use of unscaled time. I've tested with Time.timeScale = 0.0f; and this still works.
    5.         bool sameObjectAsLastClick = lastPointerDownObject == eventData.pointerCurrentRaycast.gameObject;
    7.         //if this is a double click
    8.         if (timeSinceLastClick < doubleClickTime && sameObjectAsLastClick)
    9.         {
    10.             rb.constraints = RigidbodyConstraints.None;
    11.             Debug.Log("DoubleClickAchieved!");
    12.             rb.AddForce((new Vector3(0.08f, 1, 0) * flipForce), ForceMode.Impulse);
    13.             rb.AddRelativeTorque(0, 0, flipTorque, ForceMode.Impulse);
    14.             //leftButtonIsDown = false;
    15.             waitingForSecond = false;
    16.             lastClickWasDouble = true;
    17.         }
    19.         //if it was the first click, wait to check if there's a second
    20.         else
    21.         {
    22.             StartCoroutine(DoubleTapInterval());
    23.         }
    25.         lastPointerDownObject = eventData.pointerCurrentRaycast.gameObject;
    26.         savedClickTime = (float)Touch.activeFingers[0].lastTouch.time;
    27.     }
    Is there anything obvious in the full script (attached) that might mean it won't work on the older phone?

    Attached Files:

  2. yusefkerr


    Apr 5, 2011
    Of course I solved this right after posting, but the solution is a bit weird. It turns out that I had some references to mouse events still in a 3rd party script that I'd missed, and these were causing a null reference exception when run on my older phone, but the newer phone wasn't bothered by these. At least changing those mouse input references to touch references seems to have solved the issue.