Implementing player kill zones
A common scripted feature required by all scenes, but not yet implemented, is the kill zone. This is the functionality to mark out a region of 2D space in the level that, when entered by the player, will kill or damage them. This is an especially useful tool to kill the player whenever they fall down a hole in the ground. The kill zone will be required in most levels because nearly every level created so far contains pits and holes in the ground. To implement this functionality, take the following steps:
- Create a new and empty GameObject in any scene. It doesn't matter which scene because we'll be making a prefab object that can be reused anywhere. As previously mentioned, new GameObjects are created with the menu option, GameObject | Create Empty.Â
- Once created, name the object
KillZone
. - Position the object at the world origin (
0,0,0
). - Attach a Box Collider 2D component using the menu command, Component | Physics...