Thursday, 4 May 2017

Outside the Box Project Beta Work - Toxic Defence Behaviour Update/Fix

The trouble with the Toxic Defence Behaviour script was that, although enemy health was decreasing whilst colliding with the defence and the defence's health was decreasing concurrently. When the Toxic defence was destroyed there was no way for the player to make use of the build spot left behind thereby rendering a defensive position useless.


ToxicBehaviour Script 01

ToxicBehaviour Script 02

The change to the ToxicBehaviour script from before, is that now in Update the Toxic Defence is getting a reference to the BuildDefences script and making sure it knows that when the Toxic Defence is destroyed/gone. That the Boolean that sets to True when a Defence has been built to prevent further interaction with the relevant build spot is now set to False as the Toxic Defence is gone.

 buildDefencesScript = BuildSpots(CurrentBuildSpot).GetComponent<BuildDefences>();

What this line of code does is search the BuildSpots list and finds the CurrentBuildSpot number and then gets the BuildDefences script component from the numbered Build Spot.

BuildDefences Script 01
As the BuildDefences script now requires a reference to the ToxicBehaviour script from Start, there is always an active Toxic Defence in Unity, but off screen as it not meant to be interacted with, just to provide scripting references.

BuildDefences Script 02
Spot Number is a public int (so that it can be changed in the inspector) that CurrentBuildSpot is set to every time a Toxic Defence is built.

What is essentially happening is we are getting a reference to the build spot we have just built the toxic defence on through this Spot number. We know we have built a toxic defence on the build spot closest to the Player base (for example) because the script has found the Spot Number that is on the build spot closest to the Player base. This is then how we can get a reference to just this 1 build spot and re-enable it's collider when the toxic defence is destroyed, thereby allowing the Player to build on that build spot again.



No comments:

Post a Comment