7. Name it Rocks.
8. Open it in the script editor and copy and paste the sample code from the docs.
// Instantiates prefab when any rigid body enters the trigger.
// It preserves the prefab's original position and rotation.
var prefab : Transform;
function OnTriggerEnter () {
Instantiate (prefab);
}
9. Save the script.
10. Drag it onto the Rock Zone GameObject.
Next, you’ll need a rock. There’s one in the animation test objects, but it already has an animation on it. Let’s use
the rock that came in with the ExtraTerrain Objects instead.
As you saw earlier, the usual procedure for creating a prefab is the following:
• Create an object in the scene.
• Create a new prefab in the Project view.
• Drag the object from the Hierarchy view onto the prefab.
• Delete the original from the scene.
Let’s put it into practice.
1. Locate the rock in the ExtraTerrainAssets folder.
2. Position it near the First Person Controller and scale it to about 0.25.
3. Create a new prefab in the Project view in the Adventure Prefabs folder and drag the rock
into it.
The prefab icon turns blue.
In case you noticed, the object’s name in the Hierarchy view was already blue, because it is an instance of an
asset already in the Project view.
4. To avoid confusion, let’s name this one Rock Prefab.
Your prefab is ready to use.
5. In the Hierarchy view, delete the rock from the scene.
6. Next, assign the Rock Prefab to the prefab parameter of the Rock Zone.
7. Click Play and move the First Person Controller into the Rock Zone.
The rock appears right where you placed it in the scene (Figure 11-12).
410