Android Touch Input not working in Build

I’ve seen a question like this one multiple times but it never got answered to work for me.
So, I’ve worked with Touch Input in the past but this is my first time working with Touch Input in Unity 2017. Below is my Code.
This Code works when I play the Game and test it via Unity Remote, but not in the Build.
Does anyone have a Idea? I tried so many things. :frowning:

 if (Input.GetMouseButtonDown(0))
 {
     Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     RaycastHit2D hit = Physics2D.Raycast(worldPoint, Vector2.zero);
     if (hit.collider != null)
     {
         MapTile tile = hit.transform.GetComponent<MapTile>();
         if (tile != null)
         {
             entityMovement.MoveOffset(tile.Position - Position);
             ShowWalkableTiles();
             gameManager.PlayerDidTurn();
             return;
         }
     }
 }
 /*else*/
 if (Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Ended)
 {
     Debug.Log("Touch");
     Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
     RaycastHit2D hit = Physics2D.Raycast(worldPoint, Vector2.zero);
     if (hit.collider != null)
     {
         MapTile tile = hit.transform.GetComponent<MapTile>();
         if (tile != null)
         {
             entityMovement.MoveOffset(tile.Position - Position);
             ShowWalkableTiles();
             gameManager.PlayerDidTurn();
             return;
         }
     }
 }

Try using touches instead of mouse clicks on your Android device.


Touch firstTouch = Input.GetTouch(0);
if (firstTouch.phase == TouchPhase.Began)
{
  // The touch started this is equal to a MouseDown
}

Keep in mind you should have a class to abstract your Input code from your logic.

Mouse simulation with touches can be enabled/disabled with Input.simulateMouseWithTouches option. By default this option is enabled.

It finaly worked by just using Input.touches[0] instead of Input.GetTouch(0).
No clue why though.