Destroying object on any collision
So like a lot of people new to unity I've decided I want to try making a topdown shooter. So far it's been going well, it took me a bit to make bullets shoot properly instead of float but I managed it. So now I can't belive I'm stuck on this and I'm sorry for asking what's probably a stupid question. How can i have my bullets be destroyed after colliding with anything. For this I have done
void OnCollisionEnter2d()
{
Destroy(gameObject);
}
Except that doesn't seem to work. I know the bullet is colliding with things because it bounces off of both the player and walls. Yet it doesnt do the OnCollisionEnter. The bullet has both a 2d box collider that isn't set to trigger and a 2d rigidbody. The walls also have 2d box colliders. As far a I know this should work.
If anyone would point out what I'm missing that would be great.
Thank you or your time and consideration ~minimurgle
Answer by nathanlink169 · Jun 02, 2017 at 12:18 PM
Capitalize the d in "2d"
Wow now I feel stupid. Thank you so much for pointing out. Everything works now.
Your answer
Follow this Question
Related Questions
transform.position to Rigidbody.AddForce 2 Answers
how avoided this among my player and the wall? 0 Answers
rigidbody2d bounce 2 Answers
Instantiate GameObject with Velocity 1 Answer