Creating and Destroying Game Objects

Rook Sullivan
1 min readApr 3, 2021

When working with Unity, it is important to be able to manage the objects you are using in your game environment. As part of the course, I learned how to create and then destroy a laser game object.

To begin, we first need a prefab object for our script to create. I created a capsule 3D object and scaled it down appropriately. I then moved it to a new “Prefab” folder and assigned it its own material and script.
Within the script for the Player object, I created a function that called on the Instantiate function to create a copy of my prefab object. This prefab is created at the location of the player, and has its own script that tells it to continue moving up on the screen.
Next, I needed to modify the script for the Laser object to destroy itself once it left the boundaries of the screen. The reason for this, is to reduce the amount of objects being rendered at once. If you have a thousand laser objects all moving infinitely upward, that could cause quite a performance hit.

Next, I will be working on a cooldown timer for firing the laser.

--

--

Rook Sullivan

Non-binary game dev sharing my experiences in Unity.