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”.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do…
We starting with create a CAPSULE, and scale it on 0.2 every single axis
And rename the capsule to “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”
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.
Now we add the RigidBody component at second Laser
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
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!