Death Beam Power Up!

Ryan McCoach
3 min readJul 8, 2021

--

In this article we will cover a Player power up that creates a destructive beam.

Objective:

  1. When the player picks up the Death Beam power up, it will activate the death beam.
  2. The death beam will extend from the player all the way to the top of the screen.
  3. After a set time, the death beam will turn off.

We are going to add a child object to the player that will be this death beam power up.

For the death beam sprite, I just used a previously made laser sprite and stretched it to extend all the way to the top of the screen. We will also add a Box Collider 2D and Rigidbody 2D.

Player Script

Since the death beam is a child of the player we want to be able to turn it ON or OFF when the player picks up the power up. So we will declare a GameObject in the player script and give it a serialized field attribute. Then we can assign the death beam object in the script.

In the player script we are creating a public method that will active the death child object using .SetActive(true). Then we are going to create start the coroutine that will wait a certain amount of time before turn off the death beam.

Death Beam Power Down Coroutine

The LaserBeamActivate method is called on the Power Up script when the player collides with it.

In order for the Enemies to tell the difference between a laser shot and death beam we will need to give it a tag and in the OnTriggerEnter2D for each of the Enemies we check what the death beam collided with using other.tag = “LaserBeam” (the tag we gave the death beam). Inside the IF statement we use a destroy code that will destroy ONLY the enemy and not the death beam because it will deactivate itself because of the LaserBeamPowerDown coroutine. I want to add a charging animation to this death beam, but hopefully this helped anyone else get started with a death beam!

--

--

No responses yet