The AdvanceFSM class

The AdvanceFSM class basically manages all the FSMState classes we've implemented, and keeps updated with the transitions and the current state. So, the first thing to do before using our framework is to declare the transitions and states that we plan to implement for our AI tanks.

The code in the AdvancedFSM.cs file is as follows:

using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
 
public enum Transition 
{ 
    None = 0, 
    SawPlayer, 
    ReachPlayer, 
    LostPlayer, 
    NoHealth, 
} 
 
public enum FSMStateID 
{ 
    None = 0, 
    Patrolling, 
    Chasing, 
    Attacking, 
    Dead, 
} 

It has a list object to store the FSMState objects, and two local variables to store the current ID of the FSMState class and current FSMState itself.

The ...

Get Unity Artificial Intelligence Programming - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.