Adding Damage to the Pits

This is a short and sweet affair that makes our pits into proper hazards:

1. Select the Pit Prefab in the Project View.

2. Click the Add Component button and select Scripts > ContactDamage.

3. Set the “Damage” property to a value of 2. We’re going to make falling into a pit really hurt.

4. Check the Play Hit Reaction box. Your Pit Prefab should now look similar to that shown in Figure 9.6.

Image

Figure 9.6 An updated instance of the Pit Prefab

That’s it! Load the game up and have the player jump into a pit trigger. In addition to being respawned, you’ll see damage messages in the Console. Now they’re a proper threat to the ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.