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:
In the Project view, select our ActiveBarrier prefab.
Disable its Box Collider component using its checkbox.
Open the
ActiveBarrierController.cs
script attached to it.We will need a new
built
boolean that will help us know if the barrier has finished its building process. Along with ourUISlider
andUILocalize
variables, declare the following:private bool built = false;
Now, add the following two lines at the end of the
BuildFinished()
method...