// I pass in the AI Behaviour to get access to the functions I // need for the tree public GoulBehaviourTree(BaseAIBehaviour goul) { // First I build the nodes for the tree main = new Selector(); moveToPlayer = new MoveAction(goul.Move, goul.FindPlayer); moveToPoint = new MoveAction(goul.Move, goul.GetNextPatrolPoint); huntKill.OpenBranch( //new SetVector(goul.FindPlayer, moveToPlayer.SetTarget), moveToPlayer, new ConditionalAction(goul.PlayerInRange), new ActionNode(goul.Attack)); patrol.OpenBranch( //new SetVector(goul.GetNextPatrolPoint, moveToPoint.SetTarget), moveToPoint, new WaitNode(goul.WaitForSeconds, 7f) // new ConditionalAction(goul.HasReachedPoint) ); canSeePlayer = new ThisOrThat(huntKill, patrol, goul.PlayerInView); main.OpenBranch(canSeePlayer); TreeRoot = new Root(); TreeRoot.OpenBranch(main); }
void Start() { //Get player from scene - _player = GameObject.Find("Player").transform; _aiBehaviour = this.gameObject.GetComponent <BaseAIBehaviour>(); _layerMask = ~_layerMask; }
public void Use(RaycastHit2D[] collisionInfo) { //if (TimeSinceLastAttack > AttackSpeed) //{ if (collisionInfo != null) { if (collisionInfo.Count() != 0) { IncrementValues(); foreach (RaycastHit2D hit in collisionInfo) { if (hit.transform.tag == "Enemy") { BaseAIBehaviour enemy = hit.transform.GetComponent <BaseAIBehaviour>(); enemy.IsHit = true; enemy.Health -= Damage; enemy.Velocity = -enemy.Velocity; } } } } TimeSinceLastAttack = 0f; //} }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { _ais = SetAIBehaviour(_ais, animator); _pbs = SetPlayerBehaviour(_pbs); }
private void SetFields() { _player = GameObject.FindGameObjectWithTag("Player"); _aiBehaviour = this.gameObject.GetComponent <BaseAIBehaviour>(); }