I'm using this code to raycast on objects and fire events:
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
{
var ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 20))
{
var evt = hit.collider.gameObject.GetComponent<GameEvent>();
if (evt)
{
EventManager.RegisterEvent(evt);
return;
}
}
}
But it works only on those objects with convex mesh collider. If I uncheck the convex checkbox on the mesh collider component the script stop working on that specific object.
Is there something I'm missing?