for an Android app, I have a GameObject with several children. Each of the children has a script attached and a mesh collider (with the related mesh) that turns them into buttons. Code:
void Update()
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Ray ray = myCamera.ScreenPointToRay(touch.position);
RaycastHit hitObject;
if(Physics.Raycast(ray, out hitObject))
{
GameObject hitGameObject = hitObject.transform.GetComponent<GameObject>();
TMPtext.text = "this: " + this.name;
}
}
}
When I deactivate the other children, leave only one active, and tap on it, the correct name is displayed (it’s the name of the child I have tapped on). But when all children are active, whichever I tap, the name that is displayed is for the last object in the hierarchy. I don’t understand why. I’d appreciate your input.