There's more...

We can create custom decisions and actions starting from the pseudo-abstract classes we've already created; for example, a decision on whether to attack or run away from the player.

The following code snippet demonstrates the custom Boolean decision:

using UnityEngine; 
using System.Collections; 
 
public class DecisionBool : Decision 
{ 
    public bool valueDecision; 
    public bool valueTest; 
 
    public override Action GetBranch() 
    { 
        if (valueTest == valueDecision) 
            return nodeTrue; 
        return nodeFalse; 
    } 
} 

Get Unity 2018 Artificial Intelligence Cookbook - Second 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.