GameDev : create a Laser!

Matteo Lo Piccolo
3 min readMay 11, 2021

--

We have set the Player movement, now it’s time to create a laser! At the beginning we don’t have “high fidelity graphics” so, for now, we use the “PRIMITIVE TYPE”.

We starting with create a CAPSULE, and scale it on 0.2 every single axis

Create a Capsule
Scale the Capsule

And rename the capsule to “LASER”

Laser

What we want now is this : every time we press the Space Key we fire a laser.
This introduce to us another VERY IMPORTANT concept in Unity : PREFABS.
Prefabs are object we can INSTANTIATE and RE-USE at RUN-TIME.

So, for have everything clean, we create a folder and call it “Prefabs”

Prefabs folder

Then, we DRAG AND DROP the Laser from Hierarchy to Folder

The color’s change to blue, and it means we have create a Prefab!
The concept of prefabs is :
“Have one object which SHARES information of any copy of that object!”.
This is incredible powerful!

We make a little example to clarify things :
We create another Laser from hierarchy.
To do this, select the Laser and click CTRL+D.

CTRL+D and we duplicate the Laser

Now we add the RigidBody component at second Laser

Add component, type Rigidbody and add it

Now we have one laser with RigidBody and one without, right?

BUT, if we click on “OVERRIDES” word in top right corner on the Laser WITH RigidBody and click APPLY

now we have BOTH Lasers WITH RigidBody

Both Lasers have RigidBody

This is how powerful are Prefabs : they SHARING information for each Instance of that object!

From now on, every time we create an item, we create a Prefab of that item.

To finish, we remove the duplicate of Laser.
For simple exercise we can do this:
We select again the Laser, remove RigidBody component, go to Overrides, click apply.
Now both Lasers are without RigidBody.
And we delete the second Laser.

And now we create a material for Laser
Go to Material folder, right click, create Material and name it Laser_mat

Now we drag the material on Laser

Again, we go to Overrides and click apply.

One last thing : every time we made some changes in the prefab we have to CLICK override to apply the changes.
BUT, if we change the ORIGINAL PREFAB, every ISTANCE of that prefab will AUTOMATICALY UPDATE.

With “original prefab” I mean the prefab inside PREFABS FOLDER.

See you in the next article!

--

--

Matteo Lo Piccolo
Matteo Lo Piccolo

Written by Matteo Lo Piccolo

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!

No responses yet