When the scene begins to fill up with objects, some of these objects might become complex. By complex, I mean with a lot of components and children. If we need to use many of them in the game and maybe change all of them at once, Unity offers the possibility to create a Prefab.
As the name suggests, it is an object already assembled with all the necessary components and ready to be placed in the scene. The advantage is the possibility to reuse it often and to change all its instances quickly.
To keep our project organized, let's create a folder named Prefabs
, if we haven't done so yet. Inside the folder, right-click and then select Create/Prefab
. You can name it as you want, but for this book, let's stick with Pink_Sprinkle_Projectile_Prefab
.
We already have the sprinkle in the scene, so from the Hierarchy panel, drag it into the Pink_Sprinkle_Projectile_Prefab
.
Now, we can also erase the previous sprinkle from the scene, as we don't need it anymore. For testing purposes, you can try to add as many sprinkles as you want in the scene by dragging the Prefab into the Scene view. Of course, remember to erase them before continuing with the rest of this chapter.
When we select an object that is an instance of a Prefab, three additional buttons appear in the Inspector, as shown in the following screenshot:
These are their functions:
3.145.54.7