- Home /
Question by
bork98 · Feb 12, 2015 at 08:29 PM ·
c#2d2d-platformerplatform
Type"PathDefinition" does not contain a definition for "GetPathEnumerator"
Type"PathDefinition" does not contain a definition for "GetPathEnumerator" and no extension method - Error cs1061
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 == FollowPath.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();
}
}
Comment