I’m trying to detect some objects on the screen by touching them, and recognizing them by their tag.
I’ve been playing around with the Input.Touch, but, something is wrong in my code.
public void checkHit (Collider col)
{
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
RaycastHit hit;
if (Input.touchCount >= 1)
{
if (Physics.Raycast (ray, out hit, 200))
{
switch (Input.GetTouch (0).phase)
{
case TouchPhase.Began:
if (gameObject.CompareTag ("smallI"))
{
Debug.Log ("Touched smallI");
}
else if (gameObject.CompareTag ("smallC"))
{
Debug.Log ("Touched smallC");
}
else if (gameObject.CompareTag ("smallB"))
{
Debug.Log ("Touched smallB");
}
break;
}
}
}
}
If someone has an idea of what should I change, or where to look to solve this, it’d be great!
Thanks in advance!