Creating custom Conditions is much like creating custom Actions but even easier. If you haven't taken a look at how to create Actions it is encourage that you do so, as the process is practically the same.
To create a custom Condition right-click in the Project Panel, select
Create → GameCreator → Conditionand give it a suitable name. Because the template file is a too simple Condition example, we're going to create a more complex one through this manual. We're going to create a **Condition that checks whether two objects are within a certain radius.
A Condition code is divided in a runtime section and an editor section.
The runtime section describes how it checks whether something is true or false. To do so, declare your properties below the class definition and override the
Checkmethod. To create the new Condition let's remove the
isSatisfiedproperty and create 3 others:
public Transform objectA;
public Transform objectB;
public float maxDistance = 5.0f;
And finally fill the
Check()method. To check whether
objectAis within a distance of
objectBwe calculate the distance between the two objects and return if the value is lower than the threshold.
public override bool Check(GameObject target)
if (this.objectA == null) return false;
if (this.objectB == null) return false;
float distance = Vector3.Distance(
return (distance <= this.maxDistance);