Part 2: Functioning Destroy System

Marlena Martin
2 min readMay 3, 2023

--

What we are going to do is set the game up so that if we collide with the player, we’ll destroy the enemy and if we collide with the laser, we’ll destroy the laser and enemy.

We are currently in our Enemy script in C# and previously created tags to go with each game object. Now we’ll create an if statement that says if other tag is = to tag of player, we want to destroy the enemy. We want to destroy this.gameobject as written below.

Now if we hit the laser, we want to see if the other.tag is equal to the laser tag and we’ll write it as below.

Now head back into Unity to test the code. You can duplicate the Enemy as many times as needed.

Note, make sure that in Rigid Body Use Gravity is unchecked.

Now test out your scene, you should be able to shoot at your enemy and crash into them and have them disappear.

--

--