The enemy state machine

The EnemyAI game object has its own Player.cs script, as we saw earlier, but it also has the script we're most interested in: the EnemyBehaviorTree.cs component. This component contains the BT for our enemy agent, along with some helper functionality. Let's take a look at that code now:

using UnityEngine;using System.Collections;using System.Collections.Generic;public class EnemyBehaviorTree : MonoBehaviour {        private Player playerData;     private Player ownData;    public RandomBinaryNode buffCheckRandomNode;    public ActionNode buffCheckNode;    public ActionNode healthCheckNode;    public ActionNode attackCheckNode;    public Sequence buffCheckSequence;    public Selector rootNode;

We start off with some declarations as usual. Most ...

Get Unity 2017 Game AI Programming - Third 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.