Unity3D通过FindGameObjectsWithTag获取集合排序
当通过FindGameObjectsWithTag来找相关物体,得到的集合顺序是随机的,并不是按照Hierarchy面板中的顺序。当我们需要对其进行排序时,可以借助GetSiblingIndex()来实现。
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class TestArray : MonoBehaviour {
GameObject[] Imgs;
void Start () {
Imgs =GameObject.FindGameObjectsWithTag("IMG").OrderBy(g => g.transform.GetSiblingIndex()).ToArray();
foreach (var item in Imgs)
{
Debug.Log(item.name);
}
}
}
转自:https://blog.csdn.net/u011081914/article/details/80194283
using System.Collections;
using System.Collections.Generic;