List<GameObject> planes = (from g in UnityEngine.Object.FindObjectsOfType<GameObject>() where g.name.Contains(planeName) select g).ToList();
if (planes.Count > 0)
{
int cnt = (from g in UnityEngine.Object.FindObjectsOfType<GameObject>() where g.name.StartsWith(planeName) select g).Count();
cnt -= planes.Count;
planes[0].name = planeName;
for (int i = 1; i < planes.Count; i++)
{
planes[i].name = planeName + " (" + (cnt + 1).ToString() + ")";
cnt++;
}
}
This will give me for example in the Hierarchy:
Plane (29)
Plane (28)
Plane (27)
.
.
.
.
Plane (1)
Plane
But now i want to make that the first object will be:
Plane
Plane (1)
.
.
.
.
Plane (27)
Plane (28)
Plane (29)