O'Reilly logo

Learning Unity 2D Game Development by Example by Venita Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Destroying the enemy

We are now going to destroy an enemy by spawning laser beams when we fire our spaceship. We will then use collision detection to detect when the laser beams hit the enemy ship. As soon as the enemy ship is hit, it will be destroyed.

We start a new project and add the spaceship image Rocket.png that we used previously; we will now add laser beams by using the following image:

Destroying the enemy

Let's destroy the enemy by executing the following steps:

  1. Create a new GameObject and assign the laserbeam sprite to it.
  2. Name this GameObject Bullet.
  3. Place it behind the spaceship.
  4. Select it, and within the Inspector, tag it by going to Tag | Untagged and then ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required