Instantiating and Destroying Objects in Unity

Chandler Lane
Jun 10, 2022

--

As game developers, we can give life and we can take it away. Unity lets us play god, easily.

The Instantiate() method that unity provides, gives us excellent control over bringing objects into existence. In this example, I am specifying what I want instantiated(laserPrefab), where exactly I want it(muzzleLocation.position), and the rotation it will have once instantiated( quaternion.identity). I could also add one more argument I wanted the instantiated object to have a parent.

The instantiant method also returns the game object reference that was just created.

Now for destroying.

Destroy() takes two arguments. What you want destroyed and how long until its destroyed. This is all of the control we need.

That’s that! Unity makes it easy to handle creating and destroying.

--

--