Game Development Reference
In-Depth Information
If the player character collided with the bomb, call the Explosion() function.
3.
(4) victim.GetComponent(GoRagdoll).GotoRagdoll();
(5) Instantiate (prefab, transform.position, Quaternion.identity);
(6) Destroy(gameObject);
Within the Explosion() function,
4.
Convert the player character to its ragdoll,
Instantiate a new Explosion prefab at the transform.position and rotation of
the bomb, then
5.
6.
Destroy the bomb game object.
If you playtest now, the player character will collapse and the bomb will roll according to the
collision with the player character but without the explosion effect, because it hasn't yet been
assigned as the prefab to be instantiated in the Explosion function. In the Console you will see a
UnassignedReferenceException warning you that the prefab variable has not been assigned and
suggesting that you do so.
With the Bomb game object selected, in the Inspector find the BombExplosion script component
and notice the field for the Prefab property is None. In the Project panel Assets ➤ Sample Assets
➤ Effects ➤ Particle Systems ➤ Prefabs folder find the Explosion prefab. Drag and drop it into the
Prefab property field in the Inspector.
Save the scene and save the project. Playtest and run the player character into the bomb. Nice! You
will be using more bombs later, so drag the Bomb game object from the Hierarchy into the Project
panel's Assets ➤ Prefabs folder.
Blizzard Obstacle
This simple obstacle serves as a demonstration for using particle collisions. In the editor top menu,
select Game Object ➤ Create Other ➤ Particle System and name it Blizzard. Set its Transform.
position to (-11, 11.5, 106) and Transform.rotation to (0, 90, 0).
In the Blizzard Particle System Initial module, use the Start Size drop-down menu to select Random
Between Two Constants. Leave the default settings of 0 and 1. In the Emission module, make sure
the Rate is set to 10.
The idea is for the player to have a larger volume of particles to contend with. Select Box in the
Shape module and alter its proportions to a Box X and Box Y of 5.
Check the Collision module and expand it. World means the particles will collide off any object. Be
mindful that this setting is more costly to game performance than the use of planes. Leave all the
other default settings as they are except check the Send Collision Messages box (Figure 8-10 ).
 
Search WWH ::




Custom Search