Making Enemy Fire Laser Beam

Niraj Karki
2 min readJun 6, 2021

--

Day 46- Making 2D Space Shooter Game

Objective: Creating a enemy that can shoot laser beam.

First off create a enemy that you want to shoot laser beam with. You can go through my other article if you don’t know how.

Then you need to create a empty gameobject and add laser as its child. Add collider and set it to is trigger and add rigidbody2d in child laser. Set your empty gameobject to be on the top end of the laser

After you have done this, create a script for the child laser which is going to destroy any laser it touches and damage the player.

Now create another script for the parent gameobject for laser beam and set the laser position to enemy.

Now create a OnTrigger function to find the enemy which shoots the laser beam.

Since the Enemy is going to instantiate the laser beam at its position so at start the OnTrigger is going to set active which will then store the enemy gameobject inside enemy variable. It will also start a coroutine which will start scaling a laser to make it look like a beam.

This is then going to scale the laser to 50 float value in y-axis down and 5 float in x. Then it will destroy the laser after 2 sec.

--

--

No responses yet