Instantiating and Destroying GameObjects In Unity

Objective: Instantiate an object and destroying it.

Think on a shooter game like Apex Legends, this kind of game requires to instantiate bullets every time the player shoots.

Note: I’ll be explaining how to use Object Pooling in the next article related to the topic.

Instantiating Objects In Unity

Sometimes we want to make objects to appear while the game is running when the player press a key, collides with a door or some other event. Unity give us an easy way to instatiate objects into the scene on runtime.

Using: The Instantiate() method that inherits from MonoBehaviour.

In this way we can instantiate a bullet prefab into the parent transform position without rotation.

Destroying Objects

Using the Destroy(obj) method we can destroy an object from an scene in our Unity Game.

In the example above we are destroying the same gameObject within 3 seconds.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response