Game Development Reference
In-Depth Information
Figure 8-15. Trail rendered behind the swinging pendulum obstacle
Projectile Prefab
Create a primitive sphere game object and name it Projectile. Give it a Transform.position of
(0, 0, 0), Transform.rotation of (0, 0, 0), and scale it to (0.05, 0.05, 0.05). In the Inspector, add a
Rigidbody component by selecting Add Component ➤ Physics ➤ Rigidbody.
Next, add a Trail Renderer component by selecting Add Component ➤ Effects ➤ Trail Renderer. In
the Materials property leave Size as 1. Use the circle select button to the right of the Element 0 field
to locate and select the part_afterburner material. This is a particle material from the Sample Asset
package. Set Time to 0.5 and both the Start Width and End Width to 0.1. In the Colors property,
assign a light yellow color to Color[0]. Choose successively darker yellow to orange colors for the
remaining color elements.
To make this is a more deadly obstacle, the player character should be killed when struck by the
projectile. You can use the same KillOnCollision script that you used for the pendulum obstacle by
selecting Add Component ➤ Scripts ➤ KillOnCollision.
Finally, make the Projectile game object a prefab by dragging it from the Hierarchy to the Assets ➤
Prefabs folder in the Project panel. Now you can safely delete the Projectile game object from the
Scene view.
Projectile Launcher
Create a primitive cylinder game object and name it Cannon. Give it a Transform.position of
(4, 10.5, 95), a Transform.rotation of (0, 0, 90), and a Transform.scale of (0.2, 0.2, 0.2). Now create
an empty game object and name it Launcher. The empty game object will be where the projectiles
are instantiated. In the Hierarchy drag Launcher on top of Cannon to make it a child of Cannon. Now
its Transform coordinates are relative to the Cannon game object rather than the world. Give it a
Transform.position of (0, 1.25, 0) and a Transform.rotation of (270, 270, 0), and its scale should
have reset to (5, 5, 5).
 
Search WWH ::




Custom Search