O'Reilly logo

NGUI for Unity by Charles Bernardoff

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

Handling enemy collisions

We need to handle collisions between our enemies and ActiveBarriers. Since we have a Rigidbody attached to our Enemy prefab, it will receive the OnTriggerEnter() event when it hits the collider of an ActiveBarrier GameObject.

Once the collisions with ActiveBarriers are implemented, we'll add collisions with the bottom of the screen, which will reduce the player's health.

Collisions with active barriers

First of all, we must disable the ActiveBarrier's collider by default and enable it when the barrier is built in the following manner:

  1. In the Project view, select our ActiveBarrier prefab.
  2. Disable its Box Collider component using its checkbox.
  3. Open the ActiveBarrierController.cs script attached to it.
  4. We will need a new built ...

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