60 days to become a game developer. Day 23

Ryan Brechler
3 min readDec 3, 2020

Understanding the laser…. And everything in it….

So today I am working on understanding the laser that I am creating for my player. To understand what is going on here. Lets look below on how it is created.

Adding to the player script to create a new input. The laser.

I added the new prefab that you create in unity and creating also a new script called laser. You will want to drag the laser prefab into the play script under laser. Once done you will create the behaviour as you see in the laser script like you see below.

Adding the speed, and the movement of the laser.

Once adding the logic we now have a shooting laser prefab. Now we need to clean up the spawn. As you see it does not go away and keep spawning in hierarchy. So as you see you have to do some googling and find how to destroy the object. See below the code that is highlighted. Very simple.

if (transform.position.y > 8f)
{
Destroy(this.gameObject, 5f);
}
As you can it destroys it self after it leaves the view.

We wanted to add a better spawning location for the laser so to simply add to the player script of the location for the laser to be shot from the player.

+ new Vector3(0, 0.8f, 0)

Also added a cool down system reboot in the code so that we can have a cleaner look when shooting the laser prefab.

Here you see the code being created under a private float for the fire-rate and the can fire and we also created the speed we wanted it at! Do not forget the F when putting in your speed!

We put in the if statement to give it it’s behaviour and it’s logic.

Video of the spacing between the laser.

Finally you need to remove all the notes that where put in and clean up your code. Always remember to have a clean code!

--

--

Ryan Brechler

I live my life by a quote I read off a wall in Iraq… “I refuse to tip toe through life only to arrive safely to death” Currently on the path to a new me!