November 2018
Beginner
246 pages
5h 23m
English
If the tank is hit by a bullet, then the health property's value will be decreased according to the Bullet object's damage value:
void OnCollisionEnter(Collision collision)
{
//Reduce health
if(collision.gameObject.tag == "Bullet")
{
health -=collision.gameObject.GetComponent
<Bullet>().damage;
}
}
You can open the SimpleFSM.scene file in Unity; you should see the AI tanks patrolling, chasing, and attacking the player. Our player's tank doesn't take damage from AI tanks yet, so it never gets destroyed. But AI tanks have the health property and take damage from the player's bullets, so you'll see them explode once their health property reaches zero:
Read now
Unlock full access