Game Development Reference
In-Depth Information
1.
In the LaserBeam script, add the following variable:
public GameObject hitParticles; // the sparks prefab
In the Raycast conditional, above the //update end position line, add
2.
if (hitParticles) { // if particles were assigned, instantiate them at the hit point
GameObject temp = (GameObject) Instantiate(hitParticles, hit.point,Quaternion
.FromToRotation(Vector3.up, hit.normal));
Destroy(temp, 0.3f);
}
If hitParticles have been assigned, they are instantiated at the hit point, but they are oriented to
the face normal of hit surface so they spray back towards the player. Then the prefabs are allowed to
live for 0.3 seconds before being destroyed. This solution is also commonly used to simulate bullets
hits where there is no actual mesh for the bullets. A “normal,” if you remember, is a perpendicular to
the face on the side it is drawn.
3.
Save the script.
4.
Import the Sparks.unitypackage from the Chapter 11 Assets folder, and move
it from the Prefabs root folder into the FX folder.
5.
Assign the new prefab to the Laser Point's Hit Particles parameter.
The particle system uses a Standard Assets material, but it does not recognize it as the same one
already existing in the scene. You can easily remedy the problem.
6.
Select the Sparks prefab, and open the Particle System component's
Renderer rollout.
7.
Assign the Spark material to its Material parameter.
8.
Click Play, and test.
The sparks complete the visual aspect of the laser beam nicely. The next task is to actually destroy
zombie bunnies with it. With the potato gun, you used a proximity scheme to calculate hits. With the
laser always on, you will consider only direct hits. For that functionality, you will make use of tags.
1.
Create a new tag named Invader .
2.
Assign it to the ZombieBunny prefab.
Electric slugs are oddly immune to lasers, so you can leave the Slug prefab as is.
3.
Open the LaserBeam script.
Below the hitLight.transform line, add
4.
if(hit.collider.tag == "Invader") {
hit.collider.SendMessage ("DestroyBun",SendMessageOptions.DontRequireReceiver);
}
 
Search WWH ::




Custom Search