Exemplo n.º 1
0
    // Update is called once per frame
    protected virtual void Update()
    {
        attackTimer += Time.deltaTime;

        switch (currentState)
        {
        case EnemyState.IDLE:
            pfScript.CheckSurrounding();
            break;

        case EnemyState.FOLLOW:
            if (pfScript.DistanceToPlayer() < attackRange)
            {
                anim.ResetAnimationFrame();
                currentState = EnemyState.ATTACK;
                break;
            }
            pfScript.FollowState();
            break;

        case EnemyState.ATTACK:
            player = pfScript.CheckSurrounding();

            if (player == null)
            {
                anim.ResetAnimationFrame();
                break;
            }

            Vector2 direction = player.transform.position - transform.position;
            float   distance  = direction.magnitude;

            hit = Physics2D.Raycast(transform.position, direction, distance, lineOfSightRay);

            if (hit.collider != null && hit.collider.CompareTag("Player"))
            {
                Attack();
            }
            else
            {
                currentState = EnemyState.FOLLOW;
            }
            break;

        default:
            break;
        }
    }