O'Reilly logo

Unity 2D Game Development by Dave Calabrese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Let's go huntin'!

The enemy can now kill the player on impact. Well, that's kind of one-sided, isn't it? The player needs a way to fight back! If only the player had some kind of weapon. Oh wait, they do! Let's make the player's bullets actually do something. However, we aren't going to edit the bullets, we're going to edit the enemy.

The enemy's Defense Collider object has a perfect size and position to also act as the collider that takes damage. This is a case where a collider can have multiple purposes. Let's add a new script that is specifically meant to accept damage from the player's weapon shots. Create a new script called TakeDamageFromPlayerBullet and write it up as follows:

using UnityEngine; using System.Collections; public class TakeDamageFromPlayerBullet ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required