Skip to content
Adam Graham edited this page Jan 20, 2022 · 30 revisions

FAQs


Nothing happens when bullets collide with asteroids

In the Asteroid.cs script, the code is checking when the asteroid collides with a bullet by comparing the tag of the incoming object. If nothing is happening when a bullet collides with an asteroid, it might be that you have forgotten to set the tag of your bullet prefab to "Bullet", or there could simply be a mistake in the name or spelling.

It is also possible that you are comparing the name of the incoming game object rather than the tag, gameObject.name vs gameObject.tag. It's generally a better practice to use tags over names.

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.CompareTag("Bullet"))
    {
        //...
    }
}
Clone this wiki locally