- Home /
Question by
Templarthelast · Jun 27, 2013 at 08:32 AM ·
transformarraysorting
Sorting an Transforms array by gameobject name
I'm trying to sort a list of transform objects by the gameobject name. But it doesnt seem to work. There is no error. The skript just stops there.
var potentialWaypoints : Array = waypointContainer.GetComponentsInChildren( Transform );
potentialWaypoints.sort(function(a : Transform,b : Transform) {
if(a.gameobject.name < b.gameobject.name) return -1;
if(a.gameobject.name > b.gameobject.name) return 1;
return 0;
});
Comment
Answer by mmax · Nov 17, 2013 at 11:59 AM
This worked for me:
Define sorting function
function NameCompare(a : System.Object, b : System.Object) : int
{
return CaseInsensitiveComparer().Compare(a.name,b.name);
}
Then use it:
potentialWaypoints.Sort(NameCompare);