- Home /
Problems with 2D Collision
I dont know if its because I use sprites, I want to make a prefab destroy itself when colliding with a sprite with tag "Barrier", they have Rigidbody2Ds, Box Collider 2Ds (with IsTrigger true) , same Z and they still dont collide. Can anybody identify what's wrong?
public class ShootScript : MonoBehaviour
{
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Barrier")
{
Destroy(gameObject);
}
}
}
Answer by tanoshimi · Sep 07, 2016 at 06:14 AM
If you want to register collisions, you need to set isTrigger false.
Answer by Celebration-Horse · Sep 07, 2016 at 12:35 PM
Set IsTrigger false.If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
Answer by sandeepkaur786 · Sep 07, 2016 at 11:59 AM
The script where the code is written must be applied to any of the gameobject on which collider2D is attached and the Trigger set to false. @Gunging
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Implementing 2D Sprite Collisions 1 Answer
Distribute terrain in zones 3 Answers
Text never displays count variable 1 Answer
Changing a Sprite when Collision occurs 2 Answers