Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove duplicated elements List<Vector3> Mono / C# - Unity3D

I need to remove the duplicates of elements in my Vector3 list. For Example, here is a list:

List<Vector3> PointsToGo = new List<Vector3>();

PointsToGo.Add(new Vector3(1, 1, 1));
PointsToGo.Add(new Vector3(2, 2, 2));
PointsToGo.Add(new Vector3(1, 1, 1)); // Get this one or the first one out
PointsToGo.Add(new Vector3(4, 4, 4));

Do you know how to solve this problem ? Maybe Linq can help me ?

Thanks for your answer!


1 Answers

Here is your solution

PointsToGo = PointsToGo.Distinct().ToList();

Note that you have add using System.Linq; to the top your code.

like image 60
akinmail Avatar answered Jul 02 '26 09:07

akinmail