Instantiating and Destroying Objects in Unity

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chandler Lane

Chandler Lane

Unity Developer - Professional Actor