Let's look at the real code for our AI tanks. Let's create a new class, called SimpleFSM, which inherits from our FSM abstract class.
The code in the SimpleFSM.cs file is as follows:
using UnityEngine; using System.Collections; public class SimpleFSM : FSM { public enum FSMState { None, Patrol, Chase, Attack, Dead, } //Current state that the NPC is reaching public FSMState curState; //Speed of the tank private float curSpeed; //Tank Rotation Speed private float curRotSpeed; //Bullet
[SerializeField] private GameObject Bullet; //Whether the NPC is destroyed or not private bool bDead; private int health;
// We overwrite the deprecated built-in `rigidbody` variable.
new private Rigidbody rigidbody;
Here, we declare a few...