Storing with prefabs

As we wish to fire this projectile when the player presses a key, we do not want the projectile to be in the scene by default, but instead want it to be stored and created when the key is pressed. For this reason we will store the object as a prefab, and use our script to instantiate (that is, create an instance of) it at the precise moment a key is pressed.

Note

Prefabs are Unity's way of storing GameObjects that have been set up in a particular way; for example, you may have configured an enemy soldier with particular scripts and properties that behaves a certain way. You can store this object as a prefab and instantiate it when necessary. Similarly you might have a differing soldier that behaves differently, this might be ...

Get Unity 3.x Game Development Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.