private IBehaviourTreeNode CreateGatherTreeSequence() { var builder = new BehaviourTreeBuilder(); return(builder.Sequence("gatherResources") .Do("changeColor", t => { behaviorController.ChangeColor(Color.magenta); return BehaviourTreeStatus.Success; }) .Do("findNearestResource", t => { if (behaviorController.needsResource) { target = behaviorController.GetNextResource(); behaviorController.ai.target = target; behaviorController.hasTarget = true; behaviorController.needsResource = false; return BehaviourTreeStatus.Success; } else { return BehaviourTreeStatus.Success; } }) .Do("goToResource", t => { while (behaviorController.hasTarget && !behaviorController.ai.DestinationReached() && behaviorController.ai.target.tag == "resource") { return BehaviourTreeStatus.Failure; //presumably we pause here } behaviorController.hasTarget = false; behaviorController.needsResource = true; return BehaviourTreeStatus.Success; }) .Do("checkIfAllResourcesAreGathered", t => { if (behaviorController.allResourcesGathered && behaviorController.ai.DestinationReached()) { return BehaviourTreeStatus.Success; } else { Debug.Log("All resouces found"); return BehaviourTreeStatus.Failure; } }) .End() .Build()); }