Example #1
0
    void Update()
    {
        if (CheckForPlayer > 0.0f)
        {
            CheckForPlayer -= Time.deltaTime;
        }
        else
        {
            direction = Vector3.zero;
            if (!knockbacked)
            {
                if (viewRange.PlayerInViewRange() != null)
                {
                    CheckForPlayer = 1.0f;
                    player         = viewRange.PlayerInViewRange();
                    direction      = player.transform.position - transform.position;
                }
                else if (player != null)
                {
                    if ((player.transform.position - transform.position).magnitude > followDistance)
                    {
                        CheckForPlayer = 1.0f;
                        player         = null;
                    }
                    else
                    {
                        CheckForPlayer = 1.0f;
                        direction      = player.transform.position - transform.position;
                        ChangeViewDirection();
                    }
                }
                else
                {
                    switch (viewDirection)
                    {
                    case ViewDirection.up:
                        direction = Vector3.up;
                        break;

                    case ViewDirection.down:
                        direction = Vector3.down;
                        break;

                    case ViewDirection.right:
                        direction = Vector3.right;
                        break;

                    case ViewDirection.left:
                        direction = Vector3.left;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        controller.MoveEntity(direction, movementSpeed);
    }