hello, 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=="floor")
{
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!