Game Development Reference
In-Depth Information
character has fallen to determine how much damage a fall does. However,
for this one, we'll kill with very broad strokes and say that if the character
jumps off any of the stairs very far up, he doesn't survive the fall.
Step 28: Apply DamagePlayerScript to Trigger-FallDeath. Set the Damage
Mount for the script (in the Inspector) to 100 .
Step 29: Test and play. Try jumping over the rail—an error will pop up
in the Console (which is just what we want to see) that says it can't find
Scene-ClosingFail. It means the script is working like it should and is trying
to launch the level that tells the player he failed.
Particles Doing Damage (Steam)
To add extra peril to the game, we'll make some of the pipes in the facility
spew steam. Of course, if the player walks through that steam he'll get
hurt and his health level should decrease. The steam of course will be
constructed with a particle emitter system (there is already one in the
scene if you've brought in the Scene-Hallway), or it can be brought in
as a Unity Package (Steam.unitypackage) from the supporting web site
( http://www.Creating3dGames.com ). But how to make the HealthEngine
know that the player has been hit by the steam can be accomplished in a
myriad of ways.
Unity includes a function for OnParticleCollision that can allow an object to
know when a particle has hit it and then perform actions. So, we could add a
script (or append a script) that was attached to FPC_AegisChung that watched
for particles, checked to see if the particles came from Steam, and then hit the
HealthEngineScript. But this means adding the script that does the hurting
to the player, which would really shift us away from the current system of
the player containing the health information and the objects doing the hurt
containing the script that communicates the hurting.
Or, the GameObject that contains the steam could be set up with a
raycasting mechanism so that when the player is struck by the ray, the
message to hurt him is sent. But this means that the area of pain is quite
small (within a ray), and sends the message only when the player is directly
in front of the steam.
Or, and this is the method we'll use, we can reuse the idea of a trigger. With a
trigger we can set up a broader area of influence for the steam, and then as
the character comes in contact with this influence (collides with the trigger),
the steam can tell the player's HealthEngineScript to DoDamage. With the
current mechanism, we already have things set up to take care of duration of
time within the steam.
If you wish to build your own steam package, feel free to do so. It's simply a
modified version of the Smoke particle system included with Unity's Particle
Unity Package (and renamed Steam). Under the Ellipsoid Particle Emitter
Search WWH ::




Custom Search