- Home /
Don't react to colliders in children.
I have a character in a 2D game that I need to change to collision in.
In character (collider):
function OnTriggerEnter (triggerName : Collider) {
if(triggerName.gameObject.tag == "grid") { onGrid = triggerName.gameObject; } //the onGrid variable, in turn, makes it possible to climb said grid...
if(triggerName.gameObject.tag == "monster") { Hurt(); }
}
function Attack() {
texturizer.Slice();
sword.collider.enabled = true;
yield WaitForSeconds(1);
sword.collider.enabled = false;
}
on the monsters:
function OnTriggerEnter (triggerName : Collider) {
if(triggerName.gameObject.tag == "Sword") { Die(); }
}
this is of course just a sample code to give you an idea of what I'm doing. The problem here is, that since the Sword is a child of the character (for animation purposes), the player is actually able to jump for a grid that he can't quite reach, and then attack, to reach it with his sword. I need to somehow differentiate those two colliders (triggers).
I thought it was all so simple, but just found out that Unity just passes the collisions on to the parent objects. Any way to make it NOT do that?
Your answer
Follow this Question
Related Questions
When collider enters trigger, colliders parent = triggers parent 1 Answer
Adding child Colliders to your parent object's OnTriggerStay 1 Answer
Can't click gameobject when over another trigger? 1 Answer
onTriggerEnter is unclear to me... 3 Answers
Collider.enabled working differently from inspector? 1 Answer