Hello! i’m trying to make a simple Android game in which i have to tap on an object.
the problem is that when i attach my script to the main camera I get results no matter where i touch, but i want only if i touch on my gameobject collider.
btw im using 2D mode. this is the script :
void Update()
{
if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Began))
{
Ray raycast = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit raycastHit;
if (Physics.Raycast(raycast, out raycastHit))
{
if (raycastHit.collider.CompareTag(“Egg”)) // (no, i didnt forget to add a tag)
{
//what i want to do.
}
}
}
}
}
after using raycast I dont get any results at all :/.