public override void Awake() { agent = gameObject.GetComponent <Agent>(); base.Awake(); //is player close ConditionTargetClose ctc = new ConditionTargetClose(); ctc.origin = this.gameObject; ctc.target = targetAux; ctc.minDistance = minDistance; //if player far away ConditionTargetFar ctf = new ConditionTargetFar(); ctf.origin = this.gameObject; ctf.target = targetAux; ctf.maxDistance = minDistance; //is health higher than % ConditionAgentHealthHigher cahh = new ConditionAgentHealthHigher(); cahh.target = agent; cahh.targetPercent = targetPercent; //is both above true ConditionAnd ca = new ConditionAnd(); ca.conditionA = ctc; ca.conditionB = cahh; ConditionAnd ca2 = new ConditionAnd(); ca2.conditionA = ctf; ca2.conditionB = cahh; //transition to wander state State st = GetComponent <StateWander>(); Transition transition = new Transition(); transition.condition = ca; transition.target = st; transitions.Add(transition); //transition to seek state State st2 = GetComponent <StateSeek>(); Transition transition2 = new Transition(); transition2.condition = ca2; transition2.target = st2; transitions.Add(transition2); }
private ConditionGroup ProcessConditionGroup(ActorBrain actorBrain, Dialog dialog, XmlNode node) { ConditionGroup conditions = null; if (node == null) { return(null); } string refCondition = FindChildText(node, "ref"); if (node.Name == "conditions" || node.Name == "conditionsAnd") { conditions = new ConditionAnd(actorBrain); } else if (node.Name == "conditionsOr") { conditions = new ConditionOr(actorBrain); } foreach (XmlNode childNode in node) { Condition conditionChild = ProcessCondition(actorBrain, dialog, childNode); if (conditionChild != null) { conditions.AddCondition(conditionChild); } } if (conditions != null && refCondition != null) { conditions.SetRef(refCondition); } return(conditions); }