Players tend to become frustrated quickly when faced with an enemy that they are unable to fight against. So, we are going to give our player the ability to damage and destroy the enemy tank. This will function in a similar manner to how the targets are shot.
The easiest way to weaken our enemies is to give them some health that will reduce when they are shot. We can then destroy them when they run out of health. Let's create a script with these steps to do this:
We will start by creating a new script and naming it
Health
.This script is rather short and starts with a single variable. This variable will keep track of the remaining health of the tank. By setting the default value to
3
, the tank will be able to survive three hits before being destroyed.public int health = 3;
This script also contains only one function,
Hit
. As in the case of the targets, this function is called by theBroadcastMessage
function when the player shoots at it. The first line of the function reduces...