Game Development Reference
In-Depth Information
Step 48. To heal the player you can add an object or another
particle system that increases their health while standing inside
its collider. To achieve this, add the Sparkle Rising particle system
to the Scene and give it a Box Collider with IsTrigger checked.
Create a tag for it called heal .
Step 49. The player's health can be increased while the player stands
inside the sparkles by adding the code shown in Listing 6.18 to
the pickup.js file.
Listing 6.18 Adding Another Type of Trigger and Capping
the Health
function OnTriggerStay (other : Collider)
{
if(other.gameObject.tag == "fire")
{
if(Camera.main.GetComponent("gui").health > 0)
{
Camera.main.GetComponent("gui").health =
Camera.main.GetComponent("gui").health - 1;
}
}
else if(other.gameObject.tag == "heal")
{
if(Camera.main.GetComponent("gui").health < 100)
{
Camera.main.GetComponent("gui").health =
Camera.main.GetComponent("gui").health + 1;
}
}
}
Step 50. Play. You will find that health decreases in the fire and
increases in the Sparkles. The extra if statements cap the health
between 0 and 100.
Step 51. You can complete the scenario by adding a main menu and
a game over screen, and placing keys, fires, and sparkles at a variety of
locations in the maze.
Search Nedrilad ::




Custom Search