Thursday 4 May 2017

Outside the Box Project Beta Work - Toxic Defence Behaviour


The goal of the Toxic Defence was that of a damage over time defence piece for the Player to use but one that would be destroyed if used to much, basically if this defence did damages enemies, then eventually this defence would destroy itself and something would have to be bought to replace it.

This was done for game balancing, otherwise this defence would be way too powerful.

The way this works is:
We provide a numerical value for the maximum health of the trap and it's current health.

In Start the value of the current health is equal to the value of the maximum health.

In Update (which is called every frame) we check if the value of the current health is less than or equal to 0, if so we Destroy the gameObject (lower case gameObject to inform the logic that we are destroying the gameObject this script is attached to) and we attempt to turn the collider back on on the referenced build spot, which was turned off when we bought a defence, so as to allow the player to build another defence now that this one is gone.

OnTriggerStay is better than OnTriggerEnter or OnTriggerExit for the purpose of this script as we only want to perform what is within OnTriggerStay whilst a GameObject is within the trigger, if there isn't a GameObject within the trigger, then nothing happens.

We check in OnTriggerStay if the colliding gameObject is tagged as Enemy.

If so then we grab hold of the m_EnemyHealthManagerScript component on the colliding gameObject. We do this so as to grab the health value of the enemy contextual to the one that just collided, we don't want this to affect the other Enemies that aren't currently colliding with the Toxic Defence.
We then reduce the numerical value of the colliding Enemy's health by 1 per second and reduce the current health value of the Toxic Defence by the same amount.
Effectively the Toxic Defence has a total damage output of it's maximum health value.

No comments:

Post a Comment