namespaceBehaviorDesigner.Samples
{
publicenumTaskTriggerType { Idle, Jump, SphereCollision, PlaySound }
[TaskCategory("MiniGauntlet")]
[TaskDescription("A composite task that will choose its child based on the latest collision/trigger event.")]
publicclassTaskTriggerSelector : Composite
{
// Start with the idle taskprivateintnextTaskIndex=0;
publicoverrideintCurrentChildIndex()
{
// The next task index will be 0 unless a collision or trigger event has occurredreturnnextTaskIndex;
}
publicoverridevoidOnChildExecuted(TaskStatuschildStatus)
{
// Set the next task index back to 0 immediately after the child has executed to prevent a non-idle task from running multiple tilesnextTaskIndex=0;
}
// OnTriggerEnter is called when the agent runs into a trigger that specifies what task to run textpublicoverridevoidOnTriggerEnter(Colliderother)
{
TriggerTypetriggerType=null;
if ((triggerType=other.GetComponent<TriggerType>()) !=null) {
nextTaskIndex= (int)triggerType.triggerType;
}
}
// OnCollisionEnter is called when a sphere collides with the playerpublicoverridevoidOnCollisionEnter(Collisioncollision)
{
nextTaskIndex= (int)TaskTriggerType.SphereCollision;
}
}
}