- Home /
UnitySteer - Problem creating Vector3Pathway
I started taking a look at UnitySteer. Basically I have a few waypoints in my scene, and I'm trying to assign that list of Vector3's to the C5.IList that the Vector3Pathway constructor requires.
How do I convert from a List to C5.IList ?? No matter what I try it doesn't accept the conversion, and using Path.AddPoint doesn't seem to work either using the default constructor.
When trying to convert, Unity gives me the error, 'Cannot convert from the source type to the destination type'.
Here is my code
public void Awake()
{
var vector3List = GetVectors();
Path = new Vector3Pathway((C5.IList<Vector3>)vector3List, 5, true);
}
private IList<Vector3> GetVectors()
{
wayPoints = wayPointContainer.GetComponentsInChildren<Transform>();
var vector3List = new List<Vector3>();
foreach (Transform theTransform in wayPoints)
{
vector3List.Add(new Vector3(theTransform.position.x, theTransform.position.y, theTransform.position.z));
}
return vector3List;
}
Answer by Ricardo · May 30, 2011 at 07:07 AM
What your code above is doing is trying to cast your IList into C5.IList, which is not a valid cast. There are two quick solutions I can see:
Change your GetVectors so that instead of creating a System.Collections.Generic.List you instead create a C5.ArrayList
On Awake, instead of attempting to cast that list, just construct a C5.ArrayList based on another collection (like the one you receive from GetVectors).
Thanks will try that tonight and let you know if I come right.
Thanks that works, although I'm still having an issue setting the Path property on my 'agent', please check it out on http://forum.unity3d.com/threads/26217-UnitySteer-steering-library-for-Unity/page5 thanks