- Home /
Question by
Walecznyy · Oct 30, 2015 at 09:15 PM ·
collision2d-platformerkill player
2D NPC should kill player on collision but does not.
I am currently working on a 2D game and have patrolling NPC's that should kill the player when the player collides with them and they do not and the debug does not appear. The player can collide with the NPC's but does not die. The code looks like this and has been put on the NPC. What have I done wrong?
#pragma strict
function Collision2D(coll : Collider2D){
if(coll.gameObject.tag == "Player" )
{
Destroy(coll.gameObject);
}
Debug.Log("Get rekt");
}
Comment
Answer by OncaLupe · Oct 31, 2015 at 12:06 AM
'Collision2D' is a class that holds data about a collision, not a method that gets called. What you're looking for is 'OnCollisionEnter2D'.
http://docs.unity3d.com/ScriptReference/Collider2D.OnCollisionEnter2D.html