Tip of the Day: Creating and Destroying in Unity

Insatiate

Creating a gameObject in Unity is called Instantiation and the syntax for it is:

You can further extend this command by specifying the location where you want to instantiate the object and its rotation upon instantiation.

Quaternion.Identity is used when you do not want to mess with the rotation of the object upon instantiation.

This command is useful in many cases; for example in our space project, we used it to create lasers upon hitting the space button.

Instantiating laser upon pressing Space

Destroy

Destroy GameObject is used when you want to destroy an enemy for example, destroy a pickup after using it, or it is very helpful to use it to declutter the hierarchy during game play.

The syntax is

Destroy the enemy gameObject upon contact with laser and then destroy the laser too
Destroying the laser after it is fired if it does not hit anything to remove hierarchy clutter.

A knowledge seeking biologist who is following his passion into a full time career in Unity / Game Development. https://www.linkedin.com/in/mohamed-hijazi/