Detect the collision of parent instead of the object with the Script

hello my name is Rubens Torres am Brazilian do not speak English very well sorry for any typing error this is my first post here, I have a doubt in my script C# in Unity, I have an object named Player with a script called PlayerController and have an object parented to the player named Legs, I was wondering if there is how to make the script the Player detects a collision of Player clid in this case Legs, here is my script

public class playerController : MonoBehaviour {

public GameObject legs;

void OnTriggerStay(Collider other){

if(other.gameObject.tag == “Swicth Machine”)
{
print(“Hit”);
}

}
}

with it when the player collides with the object with tag SwithcMachine print runs, but I want that to happen when collided with the Legs instead of Player, if anyone knows any solution for this, please tell how to do thanks in advance.

someone?? if they have any doubt about the matter you might ask do not know if my problem was well explained.

So, i’m trying to translate what you want.

So Legs is a child of Player? (makes more sense in my head than what you wrote)

And you want to detect when the legs are hitting the SwitchMachine object?

If I’ve interpreted this correctly…

  1. You will need colliders on the legs.

  2. I would suggest you might be able to put the same script on the legs themselves, however, I am unsure if they will receive the collisions without a rigidbody attached (note: having a rigidbody on the parent object may not work if you are looking for collisions for the legs themselves - it was a quirk with collisions, but may not still be one)

  3. You should be able to attach rigidbodies to each leg to get that part to work… Alternatively (and this is probably better), each Collision contains details of the source collider in the contacts property Unity - Scripting API: Collision.contacts. You may be able to update your script above to check the contacts and see if the contact was a leg (note: you will probably still need colliders on each leg)