Unity: Setting up the enemy laser functionality

Jake Boere
3 min readJun 17, 2021

Objective: We need to create the functionality of the enemy laser so it shots down.

To start we will work on the laser script to add the functionality of how the laser will behave. First, we will need to check if what is being fired is the enemy shot which means we need to create a bool variable that checks this.

Next, we will want to create the movement and since we have movement that moves the laser up when the player shots it we should create a new method that handles the up movement and you can just take the movement function from void update and move it to the new method.

Now to create the down movement we can create a new method that handles it and copy and paste the up movement to the down movement since we just need to make 2 changes to have working down movement. The first change will be the vector3.up will be changed to vector3.down since we want it to move down instead of up. The second change will be the condition of the if statement it will be if the transform position of Y is less than -8f.

The rest of the if statement will be the same as the move up method.

Next, we want to call those methods in void update since they handle the movement of the laser and to do this we will need an if and an else statement. The if statement will check if the enemy laser bool is false and if it is the laser moves up and the else statement will check handle the move down function.

Next, we need a method to change the is enemy laser bool to true when it’s called.

Lastly, we need to create an on trigger enter method that checks if the other tag is player and enemy laser s true then grab the player component and call the damage method in the player script.

--

--

Jake Boere

I am hard working Game development student learning as much about game development and unity as possible.