Sort game objects by tag alphabetically

Hi to everybody,

I have 56 sphere in Game which I gave tag “Waypoint”. So i have in my game Waypoint_1, Waypoint_2, Waypoint_3 … I wanted to be sorted. From 1 to 56. Now Array look randomly.

This is a code so far.

import System;

var MainWaypoints:GameObject[];
var StoreWaypoints:Array = new Array();

function Awake()
{
	MainWaypoints = GameObject.FindGameObjectsWithTag("Waypoint");
	
	for (var obj:GameObject in MainWaypoints)
	{
		StoreWaypoints.Add(obj);
	}
	
	StoreWaypoints.Sort();
	
	print("Lenght: " + StoreWaypoints.length);
	print(StoreWaypoints);
}

Every thing works great to the line when I execute Sort. I use new array becasue I thought the Sort will work. Now unity give me this error:

InvalidOperationException: No IComparable or IComparable interface found.

I realy need help how to sort game object from first number to last.

You should use a List, but for the sake of answering you question.

Use Array.Sort with the default comparer.

import System;

var MainWaypoints:GameObject[];
var StoreWaypoints:Array = new Array();

function Awake()
{
    MainWaypoints = GameObject.FindGameObjectsWithTag("Waypoint");

    StoreWaypoints = Array.Sort(MainWaypoints);

    print("Lenght: " + StoreWaypoints.length);
    print(StoreWaypoints);
}

For your reference(please use the search feature), same question answered, another one.