© Casey Hardman  2020
C. HardmanGame Programming with Unity and C#https://doi.org/10.1007/978-1-4842-5656-5_16

16. Basic Hazards

Casey Hardman1 
(1)
West Palm Beach, FL, USA
 

Now that our player can be killed, let’s start coding up some villainy to kill them. We’ll make a generic script called Hazard that makes a GameObject kill the player on touch. We’ll use this to create dangerous projectiles and an obstacle type that periodically fires them.

Collision Detection

Before we make a script that reacts to a touch, we’ll need to dive into collision detection to understand how Unity deals with such things. There are three major concepts that relate: colliders, Rigidbodies, and layers.

Colliders are components that, when added to a GameObject, give it an invisible ...

Get Game Programming with Unity and C#: A Complete Beginner’s Guide 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.