Hallo Forum, mein Problem ist folgendes:
Ich wollte ein Unity Script erstellen, das meine 2d Sprites/Gameobjekte der Größe nach sortiert. Zuerst will ich nur, dass ich die Objekte in ein Array packe und die scale werte von klein nach groß oder andersrum ausgegeben werden. Hier mein Code:
using UnityEngine;
using System;
public class Sortierer : MonoBehaviour
{
public Transform[] objects;
void Start()
{
Debug.Log(Sort(objects));
}
float[] Sort(Transform[] name1)
{
int thisIndex = 0;
float biggestVal = 0;
Transform[] name2 = name1;
float[] retVal = new float[name2.Length];
for (int j = 0; j < name2.Length; j++)
{
biggestVal = 0;
for (int i = 0; i < name2.Length; i++)
{
if (name2[i].lossyScale.x > biggestVal)
{
biggestVal = name2[i].lossyScale.x;
thisIndex = i;
}
}
retVal[j] = biggestVal;
Array.Clear(name2, thisIndex, 1);
}
return retVal;
}
}
In Unity kommt aber das:
Was mache ich da falsch?
Danke