- Home /
How to detect collisions in the children of a 2D object.
I am working on a 2D game and everything seems to be going great except for the health-bar. it works perfectly but it does not detect collisions in the objects. it goes something like this.
function OnCollisionEnter2D(coll: Collision2D) { if (coll.gameObject.tag == "Enemy" && Sheild.active == false){ isHurtin = true; } }
it detects collisions with enemies, but it only works with colliders in the Player not any of its children. how could I fix my little problem?
Answer by jonSG · Apr 16, 2014 at 12:32 PM
You could try something like this
if ( !Sheild.active && coll.transform.root.tag == "Enemy" ){ isHurtin = true; }
i forgot to mention that the children are in the player, not the enemy.
Your answer
Follow this Question
Related Questions
Lose and gain health when collision happens? 2 Answers
weapon collision with characters 1 Answer
Player take damage on collision with AI 1 Answer
Enemy not taking damage on collisions. 2 Answers
Character controller mess up damage 3 Answers