Creating Laser Weapon Mechanics

Let’s create a simple laser mechanic. To do this, we need to create several elements — a system that allows us to spawn weapons in different locations, a projectile script, and a firing mechanism.

To start, let’s create a capsule which will be our projectile.

The projectile will move up the screen based on our speed variable value. We also set this asset up so that in 2 seconds, it will destroy itself.

We also created a simple weapon script. We currently have 3 potential spawn points. I want to implement the versatility of the weapons system to either fire at the front of the ship, or from the sides, or all three at once.

Based on the _spawnPointValue, we will instantiate that capsule on a specific gun_spawn_point. We can either set it to run all points (i) or choose specifically what points we want.

All that’s left to do is add this function in our update method to pull in any inputs to fire.