Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unity Game Development Essentials

You're reading from  Unity Game Development Essentials

Product type Book
Published in Oct 2009
Publisher Packt
ISBN-13 9781847198181
Pages 316 pages
Edition 1st Edition
Languages
Author (1):
Will Goldstone Will Goldstone
Profile icon Will Goldstone

Introducing instantiation


In this section, we will learn how to spawn and duplicate objects while the game is running. This is a concept that is used in many games to create projectiles, collectable objects, and even characters, such as enemies.

In concept

Instantiation is simply a method of creating (also referred to as spawning) objects from a template (a prefab in Unity terms) during runtime. It can also be used to duplicate existing game objects already in the scene.

The approach when using instantiation will usually take this form:

  • Create the object that you wish to instantiate in your scene, and add components as necessary

  • Create a new prefab in your project, and drop the object you have been working on into that prefab

  • Delete the original object from the scene so that it is only stored as a prefab asset

  • Write a script that involves the Instantiate() command, attach it to an active game object, and set the prefab you created as the object that the Instantiate() command creates

In code

At its...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}