Let’s get backfire on our enemies
The next enemy type we will be adding into our game is 1 that knows when it is behind the player, it will shoot behind itself. To start, we will create a new game object for our enemy’s back lasers to be attached to and an offset for them so that they are fired off at the proper location:
From here, we can just create a copy of the enemy lasers and attach them to the script for the enemy. Next, we will create a new enemy type, like we did with the ramming enemy, and create it’s new methods:
In order for our enemy to know that if it is behind the player, we have to create our if statement where if the position of the enemy is lower than that of the player, we want it to shoot backwards. As we can see from the code, we have the lasers being pulled from a new script class, being EnemyLaser. After playing around with many different methods, and having little success with them, and for this moment I haven’t been able to get enough work on changing a script into a class and make it all work, I decided upon creating essentially a copy of the laser script, but change a few parts to make it suit the enemy laser. For now, it will be just set up for the back shot, but we could possibly use this new script to add in unique types of laser shots for just the enemy.
From here, we have to go into our newly created lasers and attach our new script to them, along with changing their ELaser. Once we have all of this set up, we can check to see if it works in our game:
Now that we have finally figured out how to get working back lasers, which took much longer than I had intended, we can adjust the switch statement for our enemy type spawn so that this new enemy type can come into play.
Next, we will look into adding in another new enemy type, and along with that creating a spawn rate adjuster so that we can pick which enemies we want to spawn at a higher rate.