Instantiating & Destroying Game Objects in Unity

  • right clicking in the project window and create a prefabs folder in the assets folder.
  • Now right click in the hierarchy and create your game object and drag it to the prefab folder to create your prefab.
  • Now delete the game object in the hierarchy.
  • Reference your game object
  • Instantiate it using instantiate(gameObject, position, rotation)
  • now save that and go to unity and add the prefab to the script and when you play the scene the prehab will instantiate
  • Open the script and use Destroy(this.gameObject) to destroy the cube
  • This should be done after you instantiate the game object

--

--

--

Unity Game Developer and C# Programmer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Create a Google Assistant Integration With Go

Multiples of 3 and 5 — HackerRank — Project Euler #1

Security & Dev Update

Security Development Update AMA session with Andrei Balaianu

Build your 1st Python Web App with Flask.

ML in GO or Python🤔

How to Check ‘My Collections’ on Trophee

Automation Architecture Design Pattern

Video Processing API: Cut a Video to a Shorter Length with Java

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
Matthew Clark

Matthew Clark

Unity Game Developer and C# Programmer

More from Medium

2D Mobile Game: Tilemaps

Animated Tilesets in Unity

Unity Profiler- Game Dev Series 144

Light layers in Unity HDRP