Book Image

NGUI for Unity

By : Charles Bernardoff (EURO)
Book Image

NGUI for Unity

By: Charles Bernardoff (EURO)

Overview of this book

Table of Contents (14 chapters)

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 boolean that will help us know if the barrier has finished its building process. Along with our UISlider and UILocalize variables, declare the following:

    private bool built = false;
  5. Now, add the following two lines at the end of the BuildFinished() method...