I’m trying to order points in a list from least to greatest using List.Sort(). However, I keep getting an error “ArgumentException: At least one object must implement IComparable.” I know I need to use the IComparable library and create a CompareTo method, but after looking around for a long while, I couldn’t really find a good in-depth guide for how to do this. All the documentation I found was pretty hard to understand, so I didn’t really get anywhere.
Can anyone explain what I need to do?
Vector2 playerVector = player.transform.position;
Vector2 startVector = randomPos;
Vector2 calculatedVector_1 = new Vector2(x, y_equation1);
Vector2 calculatedVector_2 = new Vector2(-x, y_equation2);
Vector2[] points = {playerVector, startVector, calculatedVector_1, calculatedVector_2};
List<Vector2> pointsOrdered = new List<Vector2>();
pointsOrdered = points.ToList();
pointsOrdered.Sort();
line.GetComponent<LineRenderer>().SetPosition(0, pointsOrdered[0]);
line.GetComponent<LineRenderer>().SetPosition(1, pointsOrdered[1]);
line.GetComponent<LineRenderer>().SetPosition(2, pointsOrdered[2]);
line.GetComponent<LineRenderer>().SetPosition(3, pointsOrdered[3]);