private EnemyState CheckTransitions(EnemyStateController enemy) { // Find player. PlayerController player = (PlayerController)enemy.GetData <PlayerController>(StateData.Player); //GameObject.FindGameObjectWithTag(Tags.Player).GetRequiredComponent<PlayerController>(); for (int transitionIndex = 0; transitionIndex < m_Transitions.Length; transitionIndex++) { EnemyState nextState; if (m_Transitions[transitionIndex].CheckTransition(enemy, player)) { nextState = m_Transitions[transitionIndex].GetTrueState; } else { nextState = m_Transitions[transitionIndex].GetFalseState; } if (nextState != null) { return(nextState); } } return(null); }
protected override void UpdateStateLogic(EnemyStateController enemy) { PlayerController player = (PlayerController)enemy.GetData <PlayerController>(StateData.Player); // Move towards the next player position. enemy.GetNavMeshAgent.destination = player.gameObject.transform.position; enemy.GetNavMeshAgent.isStopped = false; if (enemy.GetEnemyController.GetAnimator.IsAnimating == false) { enemy.GetEnemyController.GetAnimator.WalkForward(); } }
protected override void UpdateStateLogic(EnemyStateController enemy) { int patrolIndex = enemy.GetData <int>(StateData.PatrolIndex); // Move towards the next position on the patrol path. enemy.GetNavMeshAgent.destination = enemy.GetPatrolList[patrolIndex].transform.position; enemy.GetNavMeshAgent.isStopped = false; if (enemy.GetEnemyController.GetAnimator.IsAnimating == false) { enemy.GetEnemyController.GetAnimator.WalkForward(); } // Check whether the enemy has reached it's destination. if ((enemy.GetNavMeshAgent.remainingDistance <= enemy.GetNavMeshAgent.stoppingDistance) && (enemy.GetNavMeshAgent.pathPending == false)) { patrolIndex = (patrolIndex + 1) % enemy.GetPatrolList.Length; enemy.SetData(StateData.PatrolIndex, patrolIndex); } }