3

I am making a mini game and was just wondering if anyone could possibly help me with some collision detection. Currently I have an item with Rigidbody2D and a BoxCollider2D attached. It falls from the sky. I then have a floor(With a BoxCollider2D attached aswell) and when the object hits the floor, I want it to get destroyed. I am currently trying:

 void Start()
{
    gameScore = 0;
    setScore();
}

void OnCollisionEnter2D(Collider2D col)
{
    if (col.gameObject.tag=="chimney")
    {
        gameScore++;
        setScore();
        Destroy(col.gameObject);
    }
}

void setScore()
{
    scoreText.text = "Score: " + gameScore.ToString();
}

The falling objects get spawned in with instantiate()

Currently I'm getting no response from this. If anyone has any idea how this could help me, I would really appreciate it. Thanks for your time!

Note: Error now fixed!

Issue I was having here was due to me using Collider2D when I needed to use Collision2D.

SGW
  • 31
  • 5

1 Answers1

0

If it happens again or for someone else and that is not the issue it could be that the collider was never hit. I have had that happen when the object moves between frames through the object and out the other side when manually controlling an objects movement. In this case there are three ways to fix it. a thicker collider a slower object or manually controlling the collision