How to do it...

Along with the action chooser, we will create base classes for actions and goals:

  1. First, we'll create the base class for modeling actions, as shown in the following code:
using UnityEngine;using System.Collections;public class ActionGOB : MonoBehaviour{  public virtual float GetGoalChange(GoalGOB goal)  {    return 0f;  }  public virtual float GetDuration()  {    return 0f;  }}
  1. Next, we'll create the GoalGOB parent class with member variables, as shown in the following code:
using UnityEngine;using System.Collections;public class GoalGOB{  public string name;  public float value;  public float change;}
  1. Next, we'll define the proper functions for handling discontentment and change over time, as demonstrated in the following code:

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.