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. :(
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();
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();
if (tile != null)
{
entityMovement.MoveOffset(tile.Position - Position);
ShowWalkableTiles();
gameManager.PlayerDidTurn();
return;
}
}
}
↧