how to determine which trigger was hit
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?
Answer by guido-paglie · Nov 04, 2016 at 01:38 PM
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.
Your answer
Follow this Question
Related Questions
Make object active only once 0 Answers
Multiple triggers in one scene. 0 Answers
multiple objects with triggers that need to ignore the triggers but still collide with eachother? 0 Answers
How do I stop multiple spawns? 0 Answers
Hello I'm Sky, 1 Answer