我做了一個腳本,使所有多維數據集的當前場景的數組:排序遊戲對象數組的名字
public GameObject[] allCubes;
void Awake()
{
allCubes = GameObject.FindGameObjectsWithTag("cube");
}
的問題是該數組看起來像這樣的檢查:
https://i.gyazo.com/69f2f844183fe6e592e61c1517267da1.png
我已經嘗試這樣做:
public GameObject[] allCubes;
void Awake()
{
allCubes = GameObject.FindGameObjectsWithTag("cube");
Array.Sort (allCubes);
}
然而,T他給我一個錯誤:
InvalidOperationException: No IComparable or IComparable<UnityEngine.GameObject> interface found.
System.Array.compare[GameObject] (UnityEngine.GameObject value1, UnityEngine.GameObject value2, IComparer`1 comparer) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Array.cs:1756)
System.Array.qsort[GameObject,GameObject] (UnityEngine.GameObject[] keys, UnityEngine.GameObject[] items, Int32 low0, Int32 high0, IComparer`1 comparer) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Array.cs:1722)
System.Array.Sort[GameObject,GameObject] (UnityEngine.GameObject[] keys, UnityEngine.GameObject[] items, Int32 index, Int32 length, IComparer`1 comparer) (at
我該怎麼辦?
那麼你如何期待它對'GameObject'進行排序呢? – DavidG
或者,相關的問題 - *排序他們的目的*是什麼? – Adrian
@DavidG我期望他們排序像Cube1 - Cube2 - Cube2 ....但我有一種感覺,我錯了.. –