There's more...

In order to illustrate how to develop child classes deriving from the Condition function, let's take a look at a couple of examples; one that is aimed at validating a value in a range, the other at being a logic comparer between two conditions:

The code for ConditionFloat is as follows:

using UnityEngine; 
using System.Collections; 
 
public class ConditionFloat : Condition 
{ 
    public float valueMin; 
    public float valueMax; 
    public float valueTest; 
 
    public override bool Test() 
    { 
        if (valueMax >= valueTest && valueTest >= valueMin) 
            return true; 
        return false; 
    } 
} 

The following code is an example of code for ConditionAnd:

using UnityEngine; using System.Collections; public class ConditionAnd : Condition { public Condition conditionA; ...

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.