Game Development Reference
In-Depth Information
This aberration is coming from the Laser prefab's Laser script, which is attached to the child empty
Game Object. In the Assets ➤ Prefab folder, expand the Laser prefab and select the LaserBeam
child to display its properties in the Inspector (Figure 10-10 ).
Figure 10-10. The Laser's child LaserBeam in the Project panel and its Laser script component in the Inspector
There is no game object assigned to the Sparks property field, but one laser has sparks in the right
place while the rest do not. Open the Laser script in MonoDevelop. In the Start() function you'll find
the line of code assigning the Flare particle system to the sparks reference variable:
function Start () {
sparks = GameObject.Find("Flare");
The Start() function is called once. It finds the first game object named Flare and assigns it to
sparks , then moves on to execute the rest of the code block. This is why you have one laser with
sparks in the right place. Delete this line of code and save the script. Assign the Flare particle system
to the Sparks property by dragging the Flare child game object of the Laser prefab from the Project
panel (Assets/Prefabs/Laser ➤ Flare) and drop it into the Sparks property field in the Inspector.
Playtest and now the sparks all appear where the laser hits the elevated track (Figure 10-11 ).
Figure 10-11. Each of the sparks particle systems appears where its laser hits the surface of the elevated track
 
Search WWH ::




Custom Search