public override bool MoveToTarget(AIMotor aMotor)
 {
     if (m_Target == null)
     {
         aMotor.ResetState();
         return true;
     }
     float heightOffset = aMotor.agent.height * 0.5f;
     Vector3 origin = aMotor.transform.position;
     origin.y -= heightOffset;
     float distanceFromGoal = Vector3.Distance(origin, m_Target.position);
     if(distanceFromGoal < m_AttackRange)
     {
         if(m_AttackTime < 0.0f)
         {
             StartAttack();
             aMotor.agent.Stop();
             aMotor.attackType = m_Unit.selectedAbility.attackType;
             m_AttackTime = m_Unit.selectedAbility.abilityCooldown;
         }
     }
     else
     {
         m_IsAttacking = false;
         m_Motor.attackType = AttackType.NONE;
         m_Motor.attackMotion = Mathf.Lerp(m_Motor.attackMotion, 0.0f, Time.deltaTime);
         aMotor.agent.SetDestination(m_Target.position);
     }
     return false;
 }
 public override bool AquireTarget(AIMotor aMotor)
 {
     m_Motor = aMotor;
     m_Motor.isRunning = true;
     m_Unit.movementSpeed = m_RunSpeed;
     return m_Target != null;
 }
 protected virtual void Start()
 {
     m_AIMotor = GetComponent<AIMotor>();
     m_Unit = GetComponent<Unit>();
 }
 public virtual bool MoveToTarget(AIMotor aController)
 {
     return false;
 }
 public virtual bool AquireTarget(AIMotor aController)
 {
     return false;
 }
        public override bool MoveToTarget(AIMotor aController)
        {
            switch(m_State)
            {
                case AIState.MOVING_TO_GOAL:
                    m_Unit.movementSpeed = m_RunSpeed;
                    aController.isRunning = false;
                    if (m_Target != null)
                    {
                        float heightOffset = aController.agent.height * 0.5f;
                        Vector3 origin = aController.transform.position;
                        origin.y -= heightOffset;
                        float distanceFromGoal = Vector3.Distance(origin, m_Target.position);
                        if (distanceFromGoal < m_DistanceThreshHold)
                        {
                            m_Target = null;
                            //Skip Goal wait time if there is no delay
                            if(m_GoalWaitTime > 0.0f)
                            {
                                m_CurrentGoalWaitTime = m_GoalWaitTime;
                                m_State = AIState.WAITING_GOAL_DELAY;
                                return false;
                            }
                            else
                            {
                                return true;
                            }
                        }
                        else
                        {
                            aController.agent.SetDestination(m_Target.position);
                        }
                    }
                    break;
                case AIState.WAITING:
                    if(m_CurrentWaitTime < 0.0f)
                    {
                        m_State = AIState.MOVING_TO_GOAL;
                    }
                    m_CurrentWaitTime -= Time.deltaTime;
                    break;
                case  AIState.WAITING_GOAL_DELAY:
                    if(m_CurrentGoalWaitTime < 0.0f)
                    {
                        m_State = AIState.MOVING_TO_GOAL;
                        return true;
                    }
                    m_CurrentGoalWaitTime -= Time.deltaTime;
                    break;
            }

            return false;
        }
        public override bool AquireTarget(AIMotor aController)
        {
            if(m_Target == null && m_PatrolPoints.Count > 0)
            {
                //Update next node
                switch(m_Direction)
                {
                    case AIPatrolDirection.FORWARD:
                        m_CurrentStep++;
                        if(m_CurrentStep >= m_PatrolPoints.Count)
                        {
                            if(m_Pattern == AIPatrolPattern.WRAP)
                            {
                                m_CurrentStep = 0;
                            }
                            else
                            {
                                m_Direction = AIPatrolDirection.BACKWARD;
                                m_CurrentStep = m_PatrolPoints.Count - 1;
                            }

                        }
                        break;
                    case AIPatrolDirection.BACKWARD:
                        m_CurrentStep--;
                        if (m_CurrentStep < 0)
                        {
                            m_Direction = AIPatrolDirection.FORWARD;
                            m_CurrentStep = 0;
                        }
                        break;
                }
                ///Set next node
                if(m_CurrentStep >= 0 && m_CurrentStep < m_PatrolPoints.Count)
                {
                    m_Target = m_PatrolPoints[m_CurrentStep];
                }
            }
            return true;
        }
 private void Start()
 {
     m_Motor = GetComponent<AIMotor>();
     m_Unit = GetComponent<Unit>();
 }