Hello everyone. Object enemy has several Collider and triggers (one head, one body and four legs / arms), depending on where the bullet striked the enemy gets damaged (say 0.5x damage to the legs / arms, 1x damage to the body and 4x damage in the head), but how do I know which collider was hit?
Hi!
It is not recommended to have various triggers acting differently in the same gameObject.
You could have
player (parent GO)
Childs:
- Head (with trigger and script)
- Body (with trigger and script)
- Arms (with trigger and same script each arm)
- Legs (with trigger and same script each leg)
I know it seems not “elegant” but this helps to debugging and also if afterwards you need to add functionality, you will keep it clean and separately
And to call each function you could do something like this in each script:
private Player player;
void Start () {
// Find the component
player = GetComponentInParent<Player> ();
}
void OnTriggerEnter(Collider2D any) {
if (any.tag.Equals("bullet"))
player.kill ();
}
Hope it helps.