Reputation: 33
PolygonCollider2D can be composed of several paths (not only one) depending on the shape of the sprite it is applied on.
I am struggling to store all these coordinates, Vector2[], into one List.
Until now I was trying to access each path:
for (int p=0; p<polygon1.pathCount; p++)
{
polygonpoints = new Vector2[polygon1.GetPath(p).Length];
polygonpoints = polygon1.GetPath(p);
polygons.Add(polygonpoints);
}
Where polygon1 is my PolygonCollider2D and polygonPoints is a Vector2[]. polygons is a declared List[polygon1.pathcount]
Why can't I add these Vector2[] in my List ? What am I doing wrong?
Upvotes: 0
Views: 298
Reputation: 999
I believe your list just needs to be type of .
//Initialize the list with each element being a Vector2[] (Vec2 array)
List<Vector2[]> polygons = new List<Vector2[]>();
polygons.Add(polygon1.points);
Upvotes: 2