- Home /
OnCollisionEnter2D not working?
Hello. I searched up OnCollisionEnter2D and used the code it was provided with. I modified the code into
pragma strict
function OnCollisionEnter2D(coll: Collision2D) { if (coll.gameObject.tag == "Player") Destroy(gameObject); }
However, when the object collides with the Player it doesn't do anything. What am I doing wrong? I am making the game in 2D. I am also very new to Scripting and game creation.
Answer by videoanime · Feb 22, 2015 at 08:15 AM
You have to destroy it like this
Destroy(coll.gameObject);
Answer by MuppetSmash · Mar 25, 2015 at 03:25 PM
The "is trigger" on the objects collider should be unchecked, if it's checked it won't work.
Your answer
Follow this Question
Related Questions
Unity 2D Colliders not Colliding 2 Answers
[UNSOLVED] Object reference not set to an instance of an object 0 Answers
I'm getting an ERROR with a Moving Camera I'm trying to use. 0 Answers
Issue with my Teleport Script 1 Answer
WebGL build is getting cached in the browser, users cannot see updates... 0 Answers