Game Development Reference
In-Depth Information
Figure 4-17. The CreateSpheres script shown as a component of the empty game object in the Inspector
Open the CreateSpheres script in MonoDevelop. Under #pragma strict declare a new variable for
the new instance of the sphere prefab.
public var newSphere : GameObject;
In the Update() function, add the following lines of code:
if(Input.GetKey(KeyCode.Space)) {
var instance : GameObject = Instantiate(newSphere);
}
Save the script and return to the editor. Now you can see the newSphere variable that Unity prettied
up to label as “New Sphere.” Select the Prefabs folder in the Project panel. Drag the Sphere prefab
from the Project panel into GameObject's New Sphere property in the Inspector panel and drop it
over None, so that it's showing in the New Sphere area (see Figure 4-18 ).
Figure 4-18. The New Sphere variable in the Inspector panel before and after assigning the Sphere prefab
 
Search WWH ::




Custom Search