Ejemplo n.º 1
0
    void Update()
    {
        if (_haltCooldown > 0f)
        {
            _haltCooldown -= Time.deltaTime;
        }

        switch (State)
        {
        case AIState.Idle:

            if (DetectPlayer())
            {
                State = AIState.Attack;
            }
            break;

        case AIState.Attack:
            if (_shootCoolDown > 0f)
            {
                _shootCoolDown -= Time.deltaTime;
                _aiControl.LookAt(Target.position);
                break;
            }

            RaycastHit hit;
            Vector3    direction = (Target.position - transform.position).normalized;

            if (Physics.Raycast(transform.position, direction, out hit, SightDistance))
            {
                if (hit.transform != Target)
                {
                    LastKnownPlayer = Target.position;
                    State           = AIState.Idle;

                    break;
                }
                _aiControl.ShootAt(Target.position);

                _shootCoolDown = ShootCoolDown;
                break;
            }
            State = AIState.Idle;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }