2015-03-21 2 views
0

У меня возникли проблемы с ниже код:Unity 2D ошибка 1061

using System.Collections.Generic; 
using UnityEngine; 
using System.Collections; 

public class FollowPath : MonoBehaviour 
{ 
    public enum FollowType 
    { 
     MoveTowards, 
     Lerp 
    } 

    public FollowType Type = FollowType.MoveTowards; 
    public PathDefinition Path; 
    public float Speed = 1; 
    public float MaxDistanceToGoal = .1f; 

    private IEnumerator<Transform> _currentPoint; 

    public void Start() 
    { 
     if (Path == null) 
     { 
      Debug.LogError("Path cannot be null", gameObject); 
      return; 
     } 

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

     if (_currentPoint.Current == null) 
      return; 

     transform.position = _currentPoint.Current.position; 
    } 

    public void Update() 
    { 
     if (_currentPoint == null || _currentPoint.Current == null) 
      return; 

     if (Type == FollowType.MoveTowards) 
      transform.position = Vector3.MoveTowards (transform.position, 
        _currentPoint.Current.position, Time.deltaTime * Speed); 
     else if (Type == FollowType.Lerp) 
      transform.position = Vector3.Lerp(transform.position, 
        _currentPoint.Current.position, Time.deltaTime * Speed); 

     var distanceSquared = (transform.position - 
       _currentPoint.Current.position).sqrMagnitude; 
     if (distanceSquared < MaxDistanceToGoal * MaxDistanceToGoal) 
      _currentPoint.MoveNext(); 
    } 
} 

Здесь ошибка я получаю:

Активы/Код/FollowPath.cs (28,36): ошибка CS1061: Введите PathDefinition' does not contain a definition for GetPathEnumerator «а метод расширения GetPathEnumerator' of type PathDefinition» может быть найдено (вы пропали без вести с помощью директивы или ссылка на сборку?)

+0

Откуда у вас был тип PathDefinition? В документации Unity3D нет ни одного документа. В любом случае, это явно не содержит определения 'GetPathEnumerator' ... – walther

+0

FWIW, этот код также был [отправлен 12 февраля на unity3d.com] (http: /answers.unity3d.com/questions/899757/can-someone-help-me-with-this-problem.html) без ответов. – cod3monk3y

+0

@ cod3monk3y, да, я нашел его и в нескольких местах, никаких ответов. Это странно, потому что я не могу найти этот тип PathDefinition в любом месте, поэтому мне очень сложно понять, как мы должны отвечать на этот вопрос с таким количеством информации, предоставленной .. – walther

ответ

0

This СУИ пей код, похоже, исходит из видео 3DBuzz youtube Creating 2D Games in Unity 4.5 #4 - Moving Platforms. Пользователь 26dollar расшифровал код, который я автоматически отформатировал и воспроизвел здесь:

using System; 
using UnityEngine; 
using System.Collections.Generic; 
using System.Collections; 

public class PathDefinition : MonoBehaviour 
{ 
    public Transform[] Points; 

    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 (index <= 0) 
       direction = 1; 
      else if (index >= Points.Length - 1) 
       direction = -1; 

      index = index + direction; 
     } 
    } 

    public void OnDrawGizmos() 
    { 
     if (Points == null || Points.Length < 2) 
      return; 

     for (var i = 1; i < Points.Length; i++) { 
      Gizmos.DrawLine(Points[i - 1].position, Points[i].position); 
     } 
    } 
}