I have an object on which I can cast rays to check if user taps on that object. I am using the following:
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit rayHit;
bool hit = Physics.Raycast(ray, out rayHit, float.PositiveInfinity, 1 << LayerMask.NameToLayer("Kubes"));
if (hit) {
....
}
So far everything works and hit = true
when tapping the object.
At some point I clone this object using:
GameObject cloneObj = (GameObject)Instantiate(gameObject, transform.position, transform.rotation);
and for this cloned object the raycast hit does not pass.
I verified that the ray passes through the cloned object and it is. Made sure the object layer and tag are the same as the original object.
Any ideas on what am I doing wrong here?