Esempio n. 1
0
    IEnumerator IEDestination()
    {
        m_state = EAgentState.Move;
        Vector3 currPos = m_path.Pop();
        int     count   = 0;

        while (m_path.Count > 1)
        {
            yield return(null);

            if (transform.position == currPos)
            {
                currPos = m_path.Pop();
                ++count;
            }

            Vector3 prev = transform.position;
            Vector3 next = Vector3.MoveTowards(prev, currPos, m_speed * Time.deltaTime);
            m_velocity         = next - prev;
            transform.position = next;
        }
        m_currCoroutine = null;
        m_velocity      = Vector2.zero;
        m_state         = EAgentState.Standby;
    }
Esempio n. 2
0
    public void SetDestination(Vector3 position)
    {
        if (m_currCoroutine != null)
        {
            StopCoroutine(m_currCoroutine);
        }

        m_state = EAgentState.Wait;
        AStarMng.Instance.RequestPathfinding(this, transform.position, position);
    }
Esempio n. 3
0
    private void Update()
    {
        UpdateTarget();

        // If no target go back to idle
        if (!_targetFinder.Target)
        {
            _currentAgentState = EAgentState.Idle;
        }

        switch (_currentAgentState)
        {
        case EAgentState.Idle:
            if (_targetFinder.Target)
            {
                _currentAgentState = EAgentState.Move;
            }
            break;

        case EAgentState.Move:
            if (_attackComponent.IsTargetInRange(_targetFinder.Target))
            {
                _currentAgentState = EAgentState.Attack;
                _movementComponent.StopNavigation();
            }
            else
            {
                _movementComponent.OnUpdate();
            }
            break;

        case EAgentState.Attack:
            if (_attackComponent.IsTargetInRange(_targetFinder.Target))
            {
                _attackComponent.OnUpdate();
            }
            else
            {
                _currentAgentState = EAgentState.Move;
            }
            break;
        }
    }
Esempio n. 4
0
 public void Stop()
 {
     m_velocity = Vector2.zero;
     m_state    = EAgentState.Standby;
 }
Esempio n. 5
0
 public void Reset()
 {
     _currentAgentState = EAgentState.Idle;
 }