Game Development Reference
Step 5. Save and play. The plane will move upward and off the
Step 6. From the Create menu in the Project, select Prefab. Change
the name of the newly created prefab to bullet . A prefab is a game
object in waiting. It's not in the game environment, but is ready to be
called up at any time. The prefab is a template that can be used over
and over again.
Step 7. Drag and drop the plane from the Hierarchy onto the bullet in
the Project as shown in Figure 2.24 . When you click on the bullet it will
now have all the same properties as the plane. Ensure that the bullet
has its transform position set to (0,0,0), its rotation to (0,0,0), and its
scale to (0.05,0.05,0.05) in the Inspector. The bullet is going to be
attached to the rocket. To ensure its relative position to the rocket, the
bullet must be at the origin. Then when attached to the rocket it will
be located at the rocket's position coordinates.
Fig 2.24 Creating a prefab.
Step 8. Delete the original plane from the Hierarchy. It will disappear
from the Scene and Game but a template of it is now stored in the
Step 9. Open attack.js in the script editor and modify the code as
shown in Listing 2.7 . Note that as the code is getting longer only
snippets of the areas around the new code are shown. Anywhere “…”
appears assume the code in this part remains unchanged.
The variable aBullet is exposed. Select Enemy and drop the bullet
prefab from the Project onto the aBullet location in the attack script
shown in the Inspector. This is illustrated in Figure 2.25 . Because it is