How to do it...

This is a long recipe where we'll implement two extensive classes. It is advised to read the following steps carefully:

  1. Let's start by creating the class that defines our agents and its member variables:
using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
 
public class AgentAwared : MonoBehaviour 
{ 
    protected Interest interest; 
    protected bool isUpdated = false; 
} 
  1. Define the function for checking whether a given interest is relevant or not:
public bool IsRelevant(Interest i) 
{ 
    int oldValue = (int)interest.priority; 
    int newValue = (int)i.priority; 
    if (newValue <= oldValue) 
        return false; 
    return true; 
} 
  1. Implement the function for setting a new interest in the agent:
public void Notice(Interest ...

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.