2d touch not working
Hi, im trying to handle touch in my 2d mobile game but it`s acting very strange.
Here`s my code:
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
RaycastHit2D hitInfo = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position), Vector2.zero);
// RaycastHit2D can be either true or null, but has an implicit conversion to bool, so we can use it like this
if(hitInfo)
{
Debug.Log( hitInfo.transform.gameObject.name );
HandleTouch (hitInfo.transform.tag);
}
}
And:
public void HandleTouch(string objtag)
{
if (objtag == "Zone") {
canswipe = true;
} else if (objtag == "Line" && canswipe) {
current++;
canswipe = false;
SpawnParticles ();
} else {
print ("Invalid tag or canswipe = false");
}
}
Comment