PathDefinition.GetPathEnumerator C# (CSharp) Метод

GetPathEnumerator() публичный Метод

public GetPathEnumerator ( ) : IEnumerator
Результат IEnumerator
    public IEnumerator<Transform> GetPathEnumerator()
    {
        if(Points == null || Points.Length < 1)
            yield break;
        var direction = 1;
        var index = 0;
        while(true) {
            yield return Points[index];
            if(Points.Length == 1)
                continue;
            if(Type == PatrolType.Line) {
                if(index <= 0)
                    direction = 1;
                else if(index >= Points.Length -1)
                    direction = -1;
                index = index + direction;
            } else {
                if(Type == PatrolType.Circular) {
                    if(index >= Points.Length -1) {
                        index = 0;
                    } else {
                        index = index + 1;
                    }
                }
            }
        }
    }

Usage Example

Пример #1
0
    public void Start()
    {
        if (Path == null)
        {
            Debug.LogError("Path cannot be null", gameObject);
        }

        _currentPoint = Path.GetPathEnumerator();
        _currentPoint.MoveNext();

        if (_currentPoint.Current == null)
        {
            return;
        }

        transform.position = _currentPoint.Current.position;
    }
All Usage Examples Of PathDefinition::GetPathEnumerator