My Gun Isn’t Working!

Andrew Lengen
3 min readMay 29, 2021

--

We must rebuild this laser — it’s just easier that way. Let’s start by deleting the 3D “Laser” out of our “Prefabs ”folder then drag-and-drop our “Laser ”sprite from out of our “Sprites ”folder in the Project hierarchy onto our “Hierarchy”. Once it is in our Scene, resize it to whatever looks best (originally it was at a scale of 0.2 across the board) and set the “Sorting Layer” to “Foreground”!

Edit our Box Collider 2D

Next, we need to start adding the components to the Laser, similarly to the Enemy and Player: [Add Component] =>Box Collider 2D, Rigidbody 2D, and our “Laser” script from our “Scripts ” folder.

Move to “Prefabs” folder in “Project” hierarchy
Delete from scene “Hierarchy”

Edit the Box Collider 2D to your liking, set the Rigidbody 2D’s “Gravity Scale” to “0”.

After we have added all the components above, we need to move the Laser to the “Prefabs” folder, and remove it from the Hierarchy. Before we do that, we can use the Laser in the Hierarchy prepare our new off-set for the laser (I settled on 0.675) and input that new value in our _firingBasicLaser() method, then save. You can delete the Laser in the Hierarchy now!

Let’s also go through and make sure that all of our Box Collider 2D’s have their “Is Trigger” checked to avoid any funkiness and lastly make sure that in our “Player” that we set it to use our new “Laser” prefab. If you run the game now… well, the laser still doesn’t work, why? The Enemy when colliding with the Laser is searching for the Laser in through its Tag… we need to set the “Tag” on the “Laser” prefab to “Laser”!

We’re all set now! Up next I think we need to add more laser options, might tweak the speed of our player as well because we’re a little slow!

--

--

Andrew Lengen

If ambition and practicality amalgamated, it would be me! I am here to climb the mountains of my ambition and catalog my journey so that someone can be changed!