Introducing the Triple Laser
New Weapon
In this article I’ll introduce a new weapon, the Triple Laser. Although it has a slower fire rate this weapon has the ability to fire three shots at once.
Preparation
For the time being, I’ve added a few Inspector fields making it easier to make different weapon prefabs using the same behaviour. For debugging purposes I’ve added a bool indicating whether we are firing or not (for code see below).
Creating the Triple Laser Prefab
First I created a new Prefab for the Triple Laser Projectile and tagged it with “Projectile”. This prefab holds three lasers, allowing us to instantiate just one GameObject instead of three.
Creating the Triple Laser Weapon
To continue I created a new ‘TripleLaserWeapon’ Prefab, added the Weapon.cs to it, and assigned the new Projectile Prefab.
The Triple Laser holds three normal Laser Weapons, for the Player it looks like this;
In the hierarchy I also created a new parent ‘WeaponHolder’ attached to the Fighter jet, and made the weapons a child of this GameObject.
Weapon.cs update
Added a drop down field, a description area, a fire delay scrollbar and a bool for debugging.
Asteroid.cs update
I also fixed a small bug; items where being dropped more than once due to two or more projectiles being inside of the trigger collider at the time of activation. Therefor I made sure the Item is only dropped once.