예제 #1
0
    /// <summary>
    /// Make the agent follows the path
    /// </summary>
    /// <param name="_speed">speed</param>
    /// <returns></returns>
    public IEnumerator FollowPath(float _speed)
    {
        isMoving = true;
        TDS_CustomNavPath _pathToFollow = CurrentPath;
        int _index = 1;

        while (Vector3.Distance(transform.position, _pathToFollow.NavigationPoints.Last().Position) > .5f)
        {
            if (Vector3.Distance(transform.position, _pathToFollow.NavigationPoints[_index].Position) <= .5f)
            {
                _index = _index + 1;
            }
            transform.position = Vector3.MoveTowards(transform.position, _pathToFollow.NavigationPoints[_index].Position, Time.deltaTime * _speed);
            yield return(new WaitForEndOfFrame());
        }
        yield return(new WaitForEndOfFrame());

        pathState = CalculatingState.Waiting;
        isMoving  = false;
        CurrentPath.ClearPath();
        OnDestinationReached?.Invoke();
        yield break;
    }