Esempio n. 1
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;
        }
    }