- Home /
collision child with rigidbody in parent
Hello all, I need your help. I have a character(the enemy), is a gameobject with rigidbody and collider2d, to collide with walls and rocks. A child on it have collider2d, the child name back and i want when my player go behind the enemy and collide with that gameobject(Back) attacking and kill the enemy.
i have a debugig message and seams to collide but when im trying to accesse with if, the gameobject called Back doesnt work.
i have that code in my playerAttack script attached to my player gameobject
void OnCollisionEnter2D (Collision2D other)
{
Debug.Log ("Collide");
if(other.gameObject.name == "Back")
{
Animator enemyAnimator;
Debug.Log("Knife");
enemyAnimator = other.gameObject.GetComponentInParent<Animator> ();
enemyScript = other.gameObject.GetComponentInParent<Enemy>();
enemyScript.isDead = true;
enemyScript.timer = Time.time;
enemyAnimator.CrossFade("Enemy dead",0.5f);
m_Anim.CrossFade("punch",0.5f);
}
playerController.stopMoving ();
}
Any ideas? i have tried anything.. trigers removing rigidbody etc... i want the enemy collide on walls and other objects..
Thanks
Comment