void UpdatePath()
        {
            var path = _agent.FindPath(GetAgentFloorPos());

            if (path == null)
            {
                Debug.Log("There is no path there.");
                GetComponent <Dinosaur>().SetRandomGoal();
                _movementTasks = null;
                _pendingTask   = null;

                return;
            }

            _movementTasks = NodesToMoveTasks(path);

            var distance = EstimatedDistance(_movementTasks);

            _updatePathTime = distance * (1 / _pathUpdateFrequency);

            if (_movementTasks.Count > 0)
            {
                _pendingTask = _movementTasks.Dequeue();
            }

            //Debug.Log("UpdatePath(), time until next update: " + _updatePathTime);
        }
        void Update()
        {
            if (_goal == null)
            {
                GetComponent <Dinosaur>().SetRandomGoal();
            }
            float dt = Time.deltaTime;

            _elapsedTime += dt;

            var distance = (transform.position - _goal.position).magnitude;

            if (distance <= _stopDistance && (_pendingTask == null || _pendingTask.CanBeCanceled))
            {
                return;
            }

            if (_elapsedTime >= _updatePathTime && (_pendingTask == null || _pendingTask.CanBeCanceled))
            {
                _elapsedTime = 0;

                UpdatePath();
            }

            if (_pendingTask == null)
            {
                return;
            }

            var ended = _pendingTask.Update(dt);

            if (ended)
            {
                _pendingTask = _movementTasks.Count > 0 ? _movementTasks.Dequeue() : null;
            }
        }