Aspect

Next, let's take a look at the Aspect.cs class. Aspect is a very simple class with just one public property, called aspectName. That's all the variables we need in this chapter. Whenever our AI character senses something, we'll check this against the aspectName to see if it's the aspect that the AI has been looking for.

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

using UnityEngine; 
 
public class Aspect : MonoBehaviour { 
  public enum aspect { 
    Player, 
    Enemy 
  } 
  public aspect aspectName; 
} 

Attach this aspect script to our player tank and set the aspectName property as Enemy:

Setting the aspect to look out for

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.