Hazard Scripts

This section contains the final scripts that are used to control the game’s hazards. It includes the following scripts:

Image Listing A.20: The ContactDamage Script

Image Listing A.21: The PitTrigger Script

Listing A.20 The ContactDamage Script

#pragma strictpublic var damage : int = 1;public var playHitReaction : boolean = false;function OnTriggerEnter2D(collider : Collider2D){  if(collider.tag == "Player")  {    var stats : PlayerStats =collider.gameObject.GetComponent(PlayerStats);    stats.TakeDamage(this.damage, ...

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.